Author Topic: Can I use Syntax Highlighting for my Lisp code In my blog?  (Read 4970 times)

0 Members and 1 Guest are viewing this topic.

highflyingbird

  • Bull Frog
  • Posts: 415
  • Later equals never.
Can I use Syntax Highlighting for my Lisp code In my blog?
« on: December 22, 2010, 05:28:02 AM »
Can I use Syntax Highlighting for my Lisp code In my blog?(e.g, blogspot)
Thanks for your any help!
I am a bilingualist,Chinese and Chinglish.

qjchen

  • Bull Frog
  • Posts: 285
  • Best wishes to all
Re: Can I use Syntax Highlighting for my Lisp code In my blog?
« Reply #1 on: December 22, 2010, 07:27:22 AM »
http://qjchen.mjtd.com
My blog http://chenqj.blogspot.com (Chinese, can be translate into English)

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Can I use Syntax Highlighting for my Lisp code In my blog?
« Reply #2 on: December 22, 2010, 08:27:59 AM »

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Can I use Syntax Highlighting for my Lisp code In my blog?
« Reply #3 on: December 22, 2010, 09:36:51 AM »
Just add some definitions to your site's css style sheet:

Code: [Select]
/* ...*/

/******************** LISP Attributes ********************/

.function {
    font-weight: bold;
    color: yellow;
}

.command {
    font-weight: bold;
    color: yellow;
}

.call {
    color: #ff6633;
}

.comment1 {
    color: #00ff00;
}
   
.comment2 {
    color: #ff66ff;
}

.copyright {
    color: #4080ff;
}

.result {
    color: #5090ff;
}

.notes {
    color: #ffff80;
}
 
.error {
    font-weight: bold;
    color: #ff0000;
}

.data {
    color: #66ffff;
}

.alert {
    font-weight: bold;
    color: #00ffff;
}

/******************** pre definition ********************/
 
#content pre {
    background: #202020;
    font-size: 12px;
    color: #e0e0e0;
    margin: 5px 5px 10px 5px;
    padding: 5px 5px 5px 10px;
    border: 1px solid #DDDDDD;
    font-family: Consolas, "lucida console", "courier new", monospace;   
}

/* ... */

Take some code:

Code: [Select]
(defun _ToBase64 ( text )

    ;;  Copyright (c) 2008 Michael Puckett All rights reserved.
    ;;  For terms of use see http://XXXXXXXXXX.com/terms-of-use

    (if (/= "" text)

        (   (lambda ( codes map / _MaskThenShift _Map len result )

                (defun _MaskThenShift ( int mask shift )
                    (lsh (logand int mask) shift)
                )

                (defun _Map ( key ) (nth key map))

                (while (< 2 (setq len (length codes)))
                    (setq result
                        (append result
                            (mapcar '_Map
                                (list
                                    (_MaskThenShift (car codes) 252 -2)
                                    (logior
                                        (_MaskThenShift (car codes) 3 4)
                                        (_MaskThenShift (cadr codes) 240 -4)
                                    )
                                    (logior
                                        (_MaskThenShift (cadr codes) 15 2)
                                        (_MaskThenShift (caddr codes) 192 -6)
                                    )
                                    (logand (caddr codes) 63)
                                )
                            )
                        )
                        codes (cdddr codes)
                    )
                )

                (vl-list->string
                    (if (null codes) result
                        (append result
                            (mapcar '_Map
                                (if (eq 1 len)
                                    (list
                                        (_MaskThenShift (car codes) 252 -2)
                                        (_MaskThenShift (car codes) 3 4)
                                    )
                                    (list
                                        (_MaskThenShift (car codes) 252 -2)
                                        (logior
                                            (_MaskThenShift (car codes) 3 4)
                                            (_MaskThenShift (cadr codes) 240 -4)
                                        )
                                        (_MaskThenShift (cadr codes) 15 2)
                                    )
                                )
                            )
                        )
                    )
                )
            )

            (vl-string->list text)

            (_Base64Map) ;; external call

        )
        ""
    )
)

Format it accordingly for html posting (I have a proggy I'm working on (not public yet) that does it for me):

Code: [Select]
<pre>(defun <span class="function">_ToBase64</span> ( text )

    <span class="comment1">;;  Copyright (c) 2008 Michael Puckett All rights reserved.
    ;;  For terms of use see http://XXXXXXXXXX.com/terms-of-use</span>

    (if (/= "" text)

        (   (lambda ( codes map / _MaskThenShift _Map len result )

                (defun <span class="function">_MaskThenShift</span> ( int mask shift )
                    (lsh (logand int mask) shift)
                )

                (defun <span class="function">_Map</span> ( key ) (nth key map))

                (while (&lt; 2 (setq len (length codes)))
                    (setq result
                        (append result
                            (mapcar '<span class="call">_Map</span>
                                (list
                                    (<span class="call">_MaskThenShift</span> (car codes) 252 -2)
                                    (logior
                                        (<span class="call">_MaskThenShift</span> (car codes) 3 4)
                                        (<span class="call">_MaskThenShift</span> (cadr codes) 240 -4)
                                    )
                                    (logior
                                        (<span class="call">_MaskThenShift</span> (cadr codes) 15 2)
                                        (<span class="call">_MaskThenShift</span> (caddr codes) 192 -6)
                                    )
                                    (logand (caddr codes) 63)
                                )
                            )
                        )
                        codes (cdddr codes)
                    )
                )

                (vl-list-&gt;string
                    (if (null codes) result
                        (append result
                            (mapcar '<span class="call">_Map</span>
                                (if (eq 1 len)
                                    (list
                                        (<span class="call">_MaskThenShift</span> (car codes) 252 -2)
                                        (<span class="call">_MaskThenShift</span> (car codes) 3 4)
                                    )
                                    (list
                                        (<span class="call">_MaskThenShift</span> (car codes) 252 -2)
                                        (logior
                                            (<span class="call">_MaskThenShift</span> (car codes) 3 4)
                                            (<span class="call">_MaskThenShift</span> (cadr codes) 240 -4)
                                        )
                                        (<span class="call">_MaskThenShift</span> (cadr codes) 15 2)
                                    )
                                )
                            )
                        )
                    )
                )
            )

            (vl-string-&gt;list text)

            (<span class="call">_Base64Map</span>) <span class="comment2">;; external call</span>

        )
        ""
    )
)</pre>

Voila (sorry for the ugly grab: the swamp is resizing the image, here's the crispy original: http://i56.tinypic.com/35ls1th.jpg):



My bent on highlighting is I only want to see 2 variations of comments, function definitions, calls, errors, data and output. Adding colors for all functions, strings etc. just gets too garish for me and detracts from what I want to achieve: clarity showing what I've done.

An aside, many folks use a syntax highlighter by Alex Gorbatchev. Search the net, there's many adaptions, e.g. for wordpress etc. All you have to do is tweak it for lisp. I didn't go that route because I had specific wants not available with his plug-in.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Can I use Syntax Highlighting for my Lisp code In my blog?
« Reply #4 on: December 22, 2010, 09:39:34 AM »
Another couple of examples  :-)

http://lee-mac.com/attractors.html

http://lee-mac.com/layerstatus.html

I use quite a few more colours than Michael however  :lol:

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Can I use Syntax Highlighting for my Lisp code In my blog?
« Reply #5 on: December 22, 2010, 09:56:15 AM »
I use quite a few more colours than Michael however  :lol:

Nothing readability can't fix. :evil:
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Can I use Syntax Highlighting for my Lisp code In my blog?
« Reply #6 on: December 22, 2010, 10:06:01 AM »
I use quite a few more colours than Michael however  :lol:

Nothing readability can't fix. :evil:

^^ Pretty cool  8-)

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Can I use Syntax Highlighting for my Lisp code In my blog?
« Reply #7 on: December 22, 2010, 10:07:52 AM »
I use quite a few more colours than Michael however  :lol:

Nothing readability can't fix. :evil:
Very cool!
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Can I use Syntax Highlighting for my Lisp code In my blog?
« Reply #8 on: December 22, 2010, 10:54:52 AM »
I use my editor.
Code: [Select]
( (lambda (/ vim)
    (setq vim (vlax-create-object "Vim.Application"))
    (vlax-import-type-library
      :tlb-filename "C:/vim/vim72/gvim.exe"
      :methods-prefix "vimm-")
    (vimm-sendkeys vim ":e\ c:\\tmp\\lsp_file.lsp<CR>")
    (vimm-sendkeys vim ":cd\ %:p:h<CR>")
    (vimm-sendkeys vim ":TOhtml<CR>")
    (vimm-sendkeys vim ":w<CR>")
    (vimm-sendkeys vim ":close<CR>")
    (vimm-sendkeys vim ":qa<CR>")
    (vlax-release-object vim)
    (princ)
    )
 )
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Can I use Syntax Highlighting for my Lisp code In my blog?
« Reply #9 on: December 22, 2010, 11:07:10 AM »
That works pretty well John. If only I didn't hate vim. :/
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Can I use Syntax Highlighting for my Lisp code In my blog?
« Reply #10 on: December 22, 2010, 11:10:42 AM »
Hey, don't take it out on Vim; Its not Vim's fault that you like to use inferior tools.

[poke-poke]


:)
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Can I use Syntax Highlighting for my Lisp code In my blog?
« Reply #11 on: December 22, 2010, 11:14:48 AM »
 :lmao:
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Can I use Syntax Highlighting for my Lisp code In my blog?
« Reply #12 on: December 22, 2010, 11:16:27 AM »
I wrote a lsp2htm converter a long time ago.  There were a few others out there if I remember correctly. -David
R12 Dos - A2K

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Can I use Syntax Highlighting for my Lisp code In my blog?
« Reply #13 on: December 22, 2010, 01:01:31 PM »
@David
Cool colors; That kinda looks like my color scheme i created for Vim.

I know its not Lisp but Ive been playing around with Doxygen for my C++ stuff. Very cool!
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Oak3s

  • Guest
Re: Can I use Syntax Highlighting for my Lisp code In my blog?
« Reply #15 on: December 22, 2010, 04:45:29 PM »

qjchen

  • Bull Frog
  • Posts: 285
  • Best wishes to all
Re: Can I use Syntax Highlighting for my Lisp code In my blog?
« Reply #16 on: December 22, 2010, 07:20:08 PM »
Another couple of examples  :-)

http://lee-mac.com/attractors.html

http://lee-mac.com/layerstatus.html

I use quite a few more colours than Michael however  :lol:

Lee, I like your site, codes with picture or animation. ~ :-D
http://qjchen.mjtd.com
My blog http://chenqj.blogspot.com (Chinese, can be translate into English)

highflyingbird

  • Bull Frog
  • Posts: 415
  • Later equals never.
Re: Can I use Syntax Highlighting for my Lisp code In my blog?
« Reply #17 on: December 22, 2010, 08:28:21 PM »
Another couple of examples  :-)

http://lee-mac.com/attractors.html

http://lee-mac.com/layerstatus.html

I use quite a few more colours than Michael however  :lol:

Lee,your attarctors  are very cute! fabulous!

Thank all the replies. Because blogspot is blocked  in China (GFW reason) ,SO,  I can't find the answer.Now in here, I found a lot.
« Last Edit: December 22, 2010, 08:31:54 PM by highflybird »
I am a bilingualist,Chinese and Chinglish.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Can I use Syntax Highlighting for my Lisp code In my blog?
« Reply #18 on: December 23, 2010, 05:39:00 AM »
Lee, I like your site, codes with picture or animation. ~ :-D

Lee,your attarctors  are very cute! fabulous!

Thanks guys!  8-)