Coder Social home page Coder Social logo

Comments (6)

tgbugs avatar tgbugs commented on August 27, 2024

A hack for colorize:colorize-file newlines and spaces (in vim regex syntax). An offset is required not to hit the style header.

; replace newlines with <br> and a newline
s/\n/<br>\r/g
; replace spaces between tags with nbsp
s/>\zs\ \+\ze</\=substitute(submatch(0), ' ', '\&nbsp;', 'g')/g
; replace spaces between the <br>\n and another tag
s/>\n\zs\ \+\ze</\=substitute(submatch(0), ' ', '\&nbsp;', 'g')/g

from colorize.

avodonosov avatar avodonosov commented on August 27, 2024

I also have this problem - expected the colorized code to be formatted the same as original, but in HTML everything is compacted into a single line.

from colorize.

avodonosov avatar avodonosov commented on August 27, 2024

After running colorize:colorize-file I opened the generated file and wrapped the code into <pre> ... </pre> - looks good.

from colorize.

avodonosov avatar avodonosov commented on August 27, 2024

@muyinliu, it is better to change the issue title to "why newlines disappear?" or "why colorized code is compacted into a single line?". The <br> element was not the intended, the library was actually designed to wrap the code into <pre>, so the current issue title is misleading somewhat.

from colorize.

avodonosov avatar avodonosov commented on August 27, 2024

The problem is caused by mistake in the colorize-file-to-stream implementation:

Despite the default value for the encoder parameter is 'encode-for-pre

(encoder 'encode-for-pre))

the function wraps the colorized code into <tt>:
<tt>~A</tt>

Note also the docstring saying " To wrap in a <tt> element rather than <pre>, pass 'encode-for-tt
as the ENCODER." which confirms that with the default encoder the intention was
to wrap the colorized code into <pre>.

from colorize.

avodonosov avatar avodonosov commented on August 27, 2024

Workaround for the current version of the library: explicitly pass 'encode-for-tt which is consistent with the hardcoded wrapper tag <tt>...</tt>.

For that, instead of

(colorize:colorize-file :common-lisp
                        (asdf:system-relative-pathname :cl+ssl
                                                       "src/package.lisp"))

do

(let* ((input-file (asdf:system-relative-pathname :cl+ssl
                                                  "src/package.lisp"))
       (output-file (make-pathname :type "html"
                                   :defaults input-file)))
  (with-open-file (stream output-file :direction :output :if-exists :supersede)
    (colorize:colorize-file-to-stream :common-lisp
                                      input-file
                                      stream
                                      :encoder 'encode-for-tt)))

The proposed pull request #13 fixes implementation to chose the wrapper tag according to the encoder function, thus fixing colorize:colorize-file which passes 'encode-for-pre.

from colorize.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.