Comments (6)
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), ' ', '\ ', 'g')/g
; replace spaces between the <br>\n and another tag
s/>\n\zs\ \+\ze</\=substitute(submatch(0), ' ', '\ ', 'g')/g
from colorize.
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.
After running colorize:colorize-file
I opened the generated file and wrapped the code into <pre>
... </pre>
- looks good.
from colorize.
@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.
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
Line 299 in ea676b5
the function wraps the colorized code into
<tt>
:Line 324 in ea676b5
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.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
?
from colorize.