From: Duncan C. <dun...@us...> - 2005-07-27 21:16:30
|
Update of /cvsroot/gtk2hs/gtk2hs/docs/tools In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10231/docs/tools Modified Files: AddLinks.hs Log Message: Add support for 'ordinary' html, rather than xhtml. Currently doesn't do much highliting. Index: AddLinks.hs =================================================================== RCS file: /cvsroot/gtk2hs/gtk2hs/docs/tools/AddLinks.hs,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- AddLinks.hs 25 Apr 2005 11:58:32 -0000 1.1 +++ AddLinks.hs 27 Jul 2005 21:16:20 -0000 1.2 @@ -42,6 +42,7 @@ target = case map (drop 9) (filter ("--target=" `isPrefixOf`) rem) of ("tex":_) -> LaTeX + ("html":_) -> HTML ("xhtml":_) -> XHTML [] -> error "please specify --target=<target>" _ -> error "supported targets: tex, xhtml" @@ -89,7 +90,7 @@ -- to find the code snippets and to do all necesary conversion/escaping -- and add in the links and call the next bit to do any syntax highliting -- -data DocType = LaTeX | XHTML +data DocType = LaTeX | XHTML | HTML substitute :: DocType -> Concordance -> String -> [String] -> [String] substitute dt conc baseUrl = substNormal dt @@ -106,17 +107,23 @@ : substCodeArea dt codeArea ++ "</pre>" : substNormal dt ts' + substNormal HTML ("<":"pre":">":('\n':s) + :ts) = let (codeArea, ts') = findCodeArea dt (s:ts) + in "<pre>" + : substCodeArea dt codeArea + ++ "</pre>" + : substNormal dt ts' substNormal dt (t:ts) = t : substNormal dt ts findCodeArea LaTeX ("\\":"end":"{":"verbatim":"}":ts) = ([], ts) findCodeArea XHTML ("</":"pre":">" :ts) = ([], ts) + findCodeArea HTML ("</":"pre":">" :ts) = ([], ts) findCodeArea dt (t:ts) = (t:ts',ts'') where (ts',ts'') = findCodeArea dt ts substCodeArea LaTeX = map (addLinks dt) - substCodeArea XHTML = map (\(s,c) -> renderTag c (addLinks dt s)) - . map (\s -> (s,classifyToken s)) . glue - + substCodeArea XHTML = map (\s -> renderTag dt (classifyToken s) (addLinks dt s)) . glue + substCodeArea HTML = map (\s -> renderTag dt (classifyToken s) (addLinks dt s)) . glue addLinks LaTeX str | Just modName <- conc str = "\\href{" ++ haddockUrl baseUrl modName str @@ -126,6 +133,9 @@ addLinks XHTML str | Just modName <- conc str = "<a href=\"" ++ haddockUrl baseUrl modName str ++ "\">" ++ str ++ "</a>" + addLinks HTML str | Just modName <- conc str = "<a href=\"" + ++ haddockUrl baseUrl modName str + ++ "\">" ++ str ++ "</a>" addLinks _ str = str haddockUrl baseUrl modName varName = @@ -220,22 +230,37 @@ | isDigit h = Number | otherwise = Selection -renderTag :: Classification -> String -> String -renderTag Space = id -renderTag Keyword = tag "keyword" -renderTag Keyglyph = tag "keyglyph" -renderTag Layout = tag "layout" -renderTag Comment = tag "comment" -renderTag ConId = tag "conid" -renderTag VarId = tag "varid" -renderTag ConOp = tag "conop" -renderTag VarOp = tag "varop" -renderTag String = tag "string" -renderTag Char = tag "char" -renderTag Number = tag "number" -renderTag Selection = tag "selection" +renderTag :: DocType -> Classification -> String -> String +renderTag _ Space = id +renderTag XHTML Keyword = spanTag "keyword" +renderTag XHTML Keyglyph = spanTag "keyglyph" +renderTag XHTML Layout = spanTag "layout" +renderTag XHTML Comment = spanTag "comment" +renderTag XHTML ConId = spanTag "conid" +renderTag XHTML VarId = spanTag "varid" +renderTag XHTML ConOp = spanTag "conop" +renderTag XHTML VarOp = spanTag "varop" +renderTag XHTML String = spanTag "string" +renderTag XHTML Char = spanTag "char" +renderTag XHTML Number = spanTag "number" +renderTag XHTML Selection = spanTag "selection" -tag className s = "<span class=\"haskellcode-" ++ className ++ "\">" ++ s ++ "</span>" +renderTag HTML Keyword = tag "strong" +renderTag HTML Keyglyph = tag "strong" +renderTag HTML Layout = id +renderTag HTML Comment = tag "emphasis" +renderTag HTML ConId = id +renderTag HTML VarId = id +renderTag HTML ConOp = id +renderTag HTML VarOp = id +renderTag HTML String = id +renderTag HTML Char = id +renderTag HTML Number = id +renderTag HTML Selection = id + +spanTag className s = "<span class=\"haskellcode-" ++ className ++ "\">" ++ s ++ "</span>" + +tag tagName s = "<" ++ tagName ++ ">" ++ s ++ "</" ++ tagName ++ ">" -- Haskell keywords keywords = |