Permalink
Browse files

Got numbering working with xhtml inline.

  • Loading branch information...
1 parent 344095c commit 6c892076f7ebd776ff340934c6c603485c55500f @jgm committed Mar 2, 2010
Showing with 19 additions and 6 deletions.
  1. +18 −4 Text/Highlighting/Illuminate/Format.hs
  2. +1 −2 illuminate.hs
@@ -212,12 +212,26 @@ toXHtmlCSS opts toks = addLineNums source
then XHtml.table $ XHtml.tr XHtml.<< [linenumsCell minnum maxnum, mainCell x]
else x
-toXHtmlInline :: Options -> Tokens -> [XHtml.Html]
-toXHtmlInline opts = map go . F.toList . consolidate
- where go (t, s) = let styles = map stylingToCSSProperty $ optStyle opts t
+toXHtmlInline :: Options -> Tokens -> XHtml.Html
+toXHtmlInline opts toks = addLineNums source
+ where toklist = F.toList . consolidate $ toks
+ source = addPre $ XHtml.concatHtml $ map go toklist
+ go (t, s) = let styles = map stylingToCSSProperty $ optStyle opts t
in if null styles
then XHtml.stringToHtml s
- else XHtml.thespan XHtml.! [XHtml.thestyle $ concat styles] XHtml.<< s
+ else XHtml.thespan XHtml.!
+ [XHtml.thestyle $ concat styles] XHtml.<< s
+ linecount = sum $ map (length . filter (=='\n') . snd) toklist
+ addPre x = XHtml.pre XHtml.! [XHtml.thestyle "padding: 0;margin: 0;"] $ x
+ minnum = optStartNumber opts
+ maxnum = minnum + linecount - 1
+ linenumsCell x y = XHtml.td XHtml.! [XHtml.thestyle "text-align:right;background-color:#EBEBEB;padding: 0 5px 0 5px;vertical-align: baseline;"] XHtml.<<
+ addPre (XHtml.stringToHtml $ unlines (map show [x..y]))
+ mainCell x = XHtml.td XHtml.! [XHtml.thestyle "padding-left: 5px;"] XHtml.<< x
+ addLineNums x = if optNumberLines opts
+ then XHtml.table $ XHtml.tr XHtml.<<
+ [linenumsCell minnum maxnum, mainCell x]
+ else x
toHtmlCSS :: Options -> Tokens -> Html.Html
toHtmlCSS opts toks = addLineNums source
View
@@ -55,8 +55,7 @@ main = do
then if "-css" `elem` opts
then XHtml.showHtml $ XHtml.header XHtml.<< [XHtml.thetitle XHtml.<< file, XHtml.style XHtml.! [XHtml.thetype "text/css"] XHtml.<< cssFor options]
XHtml.+++ XHtml.body XHtml.<< [toXHtmlCSS options tokens]
- else XHtml.showHtml $ XHtml.pre XHtml.! [XHtml.theclass "sourceCode"] XHtml.<<
- toXHtmlInline options tokens
+ else XHtml.showHtml $ toXHtmlInline options tokens
else if "-latex" `elem` opts
then addLaTeXHeadFoot $ toLaTeX options tokens
else toANSI options tokens

0 comments on commit 6c89207

Please sign in to comment.