이전에 moniwiki 에 만들어서 쓰던 syntax highlighting 기능을 text cube 에도 가져왔다.
뭐 어디에 추가하기 그래서, Textile 플러그인에 기생을.. -_-
쓰는방법은 {{{#!emacs mode contents}}} 이런식으로 하면
저 contents 가 mode 에 맞게 fontified 된다.
대략 돌아가는 방식은 식별자를 통해 파싱해서 그 내용(contents) 을
내가 작성해둔 함수에 넘기면, contents 의 md5 를 추출하고 이전에 생성 된거면
캐쉬된 데이터를 가져오고 아니면 emacs 에 넘겨서 하이라이팅된 결과를 뽑아낸다.
htmlfontify Emacs package 를 이용했고
emacs batch mode 를 통해서 처리가 이루어 진다.
emacs 의 기능을 스크립트로 쓸수 있다니 정말 멋지지 않은가 싶다.
Emacs package : htmlfontify.el 0.20
Author: Vivek Dasmohapatra <vivek@etla.org>
뭐, php 를 잘 쓰지못해서 소스 보는데 삽질을 좀 했지만, 암튼 잘 됐다. 후후훗..
예제 소스 몇가지 ... :D
more..
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> #include <string.h> #include <sys/stat.h> #include <sys/types.h> #include <sys/socket.h> #include <arpa/inet.h> #define SERVER_PORT 9090 #define MAX_LINE 1000 /** 1. Create socket 2. Bind to address 3. Listen (Wait for connection) 4. Accept connection (If any client connection) 5. read (Read message from client) 6. write (If any write message to client) 7. repeat or close (Close connection or repeat) **/ int main(int argc, char **argv) { char ch; int state; /* state variable */ int connection; /* Connection from client */ int sock; /* server socket */ struct sockaddr_in addr_inet; int len_inet; sock = socket(AF_INET, SOCK_STREAM, 0); memset(&addr_inet,0, sizeof(addr_inet)); addr_inet.sin_family = AF_INET; addr_inet.sin_port = htons(SERVER_PORT); /* set PORT NUMBER */ inet_aton("localhost", &addr_inet.sin_addr); len_inet = sizeof(addr_inet); /* Bind to address */ state = bind (sock, (struct sockaddr *)&addr_inet, len_inet); if ( state == -1 ) { fprintf(stderr, "%s : bind error", strerror(errno)); exit(EXIT_FAILURE); /* Failture */ } if ( listen(sock, 1024) < 0 ) { fprintf(stderr, "%s : listen error", strerror(errno)); exit(EXIT_FAILURE); } while ( 1 ) { /* Wait for a connection, then accept() it */ if ( (connection = accept(sock, NULL, NULL) ) < 0 ) { fprintf(stderr, "%s : accept error\n", strerror(errno)); exit(EXIT_FAILURE); } while ( (state = read(connection, &ch, 1)) != 0) { printf("%c", ch); /* Print message character by character */ } /* Close the connected socket */ if ( close(connection) < 0 ) { fprintf(stderr, "%s : close error\n", strerror(errno)); exit(EXIT_FAILURE); } sleep(1); /* Take a rest for one second You can use also delay(1000) */ } close(sock); return 0; }
import java.util.Scanner; public class DoTowers { static int count; // use static variable public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(sc.hasNext()) { int input; input = sc.nextInt(); if (input < 0 ) break; else DoTowers.doTowers(input, 1, 2, 3); } } public static void doTowers( int n, int startPeg, int auxPeg, int endPeg) { count = 0; __doTowers(n, startPeg, auxPeg, endPeg); /* print out the number of moving */ System.out.println("doTower(" + n + ") = ring moved " + count); } public static void __doTowers( int n, int startPeg, int auxPeg, int endPeg) { if (n > 0) { __doTowers(n - 1, startPeg, endPeg, auxPeg); __doTowers(n - 1, auxPeg, startPeg, endPeg); count++; /* count the number of moving */ } } }
;; web font lock code (setq window-system nil) (setq load-path (cons (expand-file-name "/home/jaram/maya/.emacs.d/color-theme") load-path)) (setq load-path (cons (expand-file-name "/home/jaram/maya/.emacs.d/htmlfontify") load-path)) (setq load-path (cons (expand-file-name "/home/jaram/maya/.emacs.d/php-mode") load-path)) (setq load-path (cons (expand-file-name "/home/jaram/maya/.emacs.d/tuareg-mode") load-path)) (require 'htmlfontify) (require 'color-theme) (require 'tuareg) (require 'caml) (require 'php-mode) (global-font-lock-mode t) (color-theme-initialize) (color-theme-deep-blue) (defun web-fontify (mode uniq) (let ((cache-dir "/tmp/")) (set-buffer "*scratch*") (find-file (concat cache-dir uniq)) (funcall mode) (font-lock-fontify-buffer) ; do fontify (let ((my-buf (htmlfontify-buffer uniq))) (set-buffer my-buf) (princ (buffer-string))))) ; print out the result to stdin

글
댓글을 달아 주세요
댓글 RSS 주소 : http://maya.jaram.org/blog/bth/rss/comment/2댓글 ATOM 주소 : http://maya.jaram.org/blog/bth/atom/comment/2