Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Ddoc: »HTML source« files for DDoc-only modules. #4

Open
wants to merge 2 commits into from

2 participants

David Nadlinger Aziz Köksal
David Nadlinger

This avoids broken links (e.g. from the linked module headlines).

David Nadlinger

Feel free to come up with a different solution, but having broken links all over the generated output for DDoc-only modules is not nice.

Aziz Köksal
Owner

Thanks. I'll have a careful look when I have the time. At the moment I don't even have a regular and reliable internet connection. Life's hard. :-)

David Nadlinger

Yeah, same here (well, it's not the internet connection which is the problem for me) – just wanted to post it so it doesn't get lost.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

Nov 08, 2011
David Nadlinger klickverbot Ddoc: »HTML source« files for DDoc-only modules.
This avoids broken links (e.g. from the linked module headlines).
95453e5
David Nadlinger klickverbot Ddoc: Process Ddoc-only modules (e.g. syntax-highlight code blocks). f15cc4e
This page is out of date. Refresh to see the latest.
9 src/cmd/DDoc.d
@@ -118,7 +118,7 @@ class DDocCommand : Command
118 118 auto mod = new Module(filePath, context);
119 119
120 120 // Only parse if the file is not a "Ddoc"-file.
121   - if (!DDocEmitter.isDDocFile(mod))
  121 + if (!mod.isDDocFile)
122 122 {
123 123 if (mm.moduleByPath(mod.filePath()))
124 124 continue; // The same file path was already loaded. TODO: warning?
@@ -139,8 +139,13 @@ class DDocCommand : Command
139 139 auto pass1 = new SemanticPass1(mod, context);
140 140 pass1.run();
141 141 }
142   - else // Normally done in mod.parse().
  142 + else
  143 + {
  144 + // Normally done in mod.parse().
143 145 mod.setFQN(Path(filePath).name());
  146 + if (writeHLFiles)
  147 + writeSyntaxHighlightedFile(mod);
  148 + }
144 149
145 150 // Write the documentation file.
146 151 writeDocumentationFile(mod, mtable);
30 src/dil/Highlighter.d
@@ -108,13 +108,41 @@ class Highlighter
108 108 void highlightSyntax(string filePath, bool printHTML, bool opt_printLines)
109 109 {
110 110 auto modul = new Module(filePath, cc);
111   - modul.parse();
  111 + if (!modul.isDDocFile)
  112 + modul.parse();
112 113 highlightSyntax(modul, printHTML, opt_printLines);
113 114 }
114 115
115 116 /// ditto
116 117 void highlightSyntax(Module modul, bool printHTML, bool opt_printLines)
117 118 {
  119 + if (modul.isDDocFile)
  120 + {
  121 + print.format(tags["DocHead"], modul.getFQN());
  122 +
  123 + auto text = modul.sourceText.text;
  124 +
  125 + if (opt_printLines)
  126 + {
  127 + size_t lineCount;
  128 + foreach (dchar c; text)
  129 + {
  130 + if (c == '\n')
  131 + ++lineCount;
  132 + }
  133 +
  134 + print(tags["LineNumberBegin"]);
  135 + printLines(lineCount);
  136 + print(tags["LineNumberEnd"]);
  137 + }
  138 +
  139 + print(tags["SourceBegin"]);
  140 + print(text);
  141 + print(tags["SourceEnd"]);
  142 + print(tags["DocEnd"]);
  143 + return;
  144 + }
  145 +
118 146 auto parser = modul.parser;
119 147 auto lx = parser.lexer;
120 148 auto builder = new TokenExBuilder();
18 src/dil/doc/DDocEmitter.d
@@ -25,7 +25,7 @@ import dil.Highlighter,
25 25 dil.Enums;
26 26 import common;
27 27
28   -import tango.text.Ascii : toUpper, icompare;
  28 +import tango.text.Ascii : toUpper;
29 29
30 30 /// Traverses the syntax tree and writes DDoc macros to a string buffer.
31 31 abstract class DDocEmitter : DefaultVisitor2
@@ -65,7 +65,7 @@ abstract class DDocEmitter : DefaultVisitor2
65 65 /// Entry method.
66 66 char[] emit()
67 67 {
68   - if (isDDocFile(modul))
  68 + if (modul.isDDocFile)
69 69 { // The module is actually a DDoc text file.
70 70 auto c = DDocUtils.getDDocComment(getDDocText(modul));
71 71 foreach (s; c.sections)
@@ -75,7 +75,7 @@ abstract class DDocEmitter : DefaultVisitor2
75 75 mtable.insert(ms.macroNames, ms.macroTexts);
76 76 }
77 77 else
78   - write(s.wholeText);
  78 + write(scanCommentText(s.wholeText));
79 79 return text;
80 80 }
81 81
@@ -189,18 +189,6 @@ abstract class DDocEmitter : DefaultVisitor2
189 189 }
190 190 }
191 191
192   - /// Returns true if the source text starts with "Ddoc\n" (ignores letter case.)
193   - static bool isDDocFile(Module mod)
194   - {
195   - auto data = mod.sourceText.data;
196   - // 5 = "ddoc\n".length; +1 = trailing '\0' in data.
197   - if (data.length >= 5 + 1 && // Check for minimum length.
198   - icompare(data[0..4], "ddoc") == 0 && // Check first four characters.
199   - isNewline(data.ptr + 4)) // Check for a newline.
200   - return true;
201   - return false;
202   - }
203   -
204 192 /// Returns the DDoc text of this module.
205 193 static char[] getDDocText(Module mod)
206 194 {
16 src/dil/semantic/Module.d
@@ -6,7 +6,8 @@ module dil.semantic.Module;
6 6 import dil.ast.Node,
7 7 dil.ast.Declarations;
8 8 import dil.parser.Parser;
9   -import dil.lexer.Lexer,
  9 +import dil.lexer.Funcs,
  10 + dil.lexer.Lexer,
10 11 dil.lexer.IdTable;
11 12 import dil.semantic.Symbol,
12 13 dil.semantic.Symbols;
@@ -20,6 +21,7 @@ import common;
20 21
21 22 import tango.io.model.IFile,
22 23 tango.io.device.File;
  24 +import tango.text.Ascii : icompare;
23 25 import tango.text.Util;
24 26
25 27 alias FileConst.PathSeparatorChar dirSep;
@@ -197,4 +199,16 @@ class Module : ModuleSymbol
197 199 FQNPath[i] = dirSep;
198 200 return FQNPath;
199 201 }
  202 +
  203 + /// Returns true if the source text starts with "Ddoc\n" (ignores letter case.)
  204 + bool isDDocFile()
  205 + {
  206 + auto data = this.sourceText.data;
  207 + // 5 = "ddoc\n".length; +1 = trailing '\0' in data.
  208 + if (data.length >= 5 + 1 && // Check for minimum length.
  209 + icompare(data[0..4], "ddoc") == 0 && // Check first four characters.
  210 + isNewline(data.ptr + 4)) // Check for a newline.
  211 + return true;
  212 + return false;
  213 + }
200 214 }

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.