=
// This is new code for Web7.
@ Huh. I printed the internal representation and the types aren't what I expect.
SSection("", PARAGRAPH, [
SBlock(PARAGRAPH, 18, ""),
SBlock(CODE, 16, "I really want to redefine existing sections and dynamically add content into group sections.\r\n\r\n")])
@*Escaping @s. Did some debugging. The problem isn't in the parser continuing to read the second at as a command, but in leaving stray angle brackets <content> in an HTML file. Because while my code is escaped, my content isn't. Hmm. This is a deeper design issue. I want @<Token@> to render and <b> to bold.
@ The program is doing the right thing. Can I add a warning message that I might be doing the wrong thing? @@<tag> won't render correctly because HTML thinks it's a tag. < hello there>
@=
SSection[] parse_web(ref string outputDisplayContents, ref string outputCodeContents, string fileContents, string inputFilename)
{
...
while(charIndex < fileContents.length) {
dchar ch = fileContents[charIndex];
if(ch == '@@') {
dchar chNext = charIndex < fileContents.length - 1 ? fileContents[charIndex + 1] : 0;
if(chNext == '@@') {
// It's just an escaped at. Continue parsing.
@ Let's insert an extra check for raw less than that may be interpreted as HTML tags.
@=
if(charIndex < fileContents.length - 1 && fileContents[charIndex] == '<' && fileContents[charIndex + 1] != ' ') {
// I think the writer wrote at, at, lessthan to try and escape the at, but the lessthan will be problematic in HTML.
writefln("Warning: Using %s%stag in an HTML file may have unintended effects. Near line %d in %s.", CHAR_AT, '<', lineNumber, inputFilename);
}
@ And we need the same fix inside slurp_section.
@=
if(index < contents.length - 1 && contents[index+1] == '<' && contents[index + 2] != ' ') {
// I think the writer wrote at, at, lessthan to try and escape the at, but the lessthan will be problematic in HTML.
writefln("Warning: Using %s%stag in an HTML file may have unintended effects. Near line %d in %s.", CHAR_AT, '<', lineNumber, inputFilename);
}
@ Let's test this : @@<an error@@>? - It works.
Warning: Using @@<tag in an HTML file may have unintended effects. Near line 207
@*Custom Formatters. This implementation can do bold text, italic text, and bold italic terms. I need an inline code style and maybe another. I want to define a style and be able to apply it.
@
@@#define A=<b><i>content</i></b>
...
@@ This is a paragraph with @@Asome styling@@>.
@ would yield : This is a paragraph with some styling.
@ In |New Display Work in parse_web_then_tangle_and_weave| is this:
@=
foreach(SSection section; fileSections) {
if(section.type != ESectionType.CODE) {
string paragraphReducer(string output, SBlock block) {
if(block.type == ESectionType.INDEX_TERM) {
return output ~ "" ~ block.content.strip("|") ~ "";
} else if(block.type == ESectionType.BOLD) {
return output ~ "" ~ block.content ~ "";
} else if(block.type == ESectionType.PRE) {
return output ~ "" ~ block.content ~ "";
@ I'll hack WEB4 so I can improve those tags.
@ Before BOLD and PRE were separate types, I'm going to fold them into just CUSTOM.
@=
CUSTOM,
@ The SBlock type now can have the type be CUSTOM and the exact formatter specified here.
@=
string customFormat;
@ SFormat is a new type which will define the tags.
@=
struct SFormat{
string pre;
string post;
};
@
@=
SFormat[string] Custom_formats;
@ To preserve backward compatibility, bold and italic are defined as custom formatters.
@=
Custom_formats["^"]=SFormat("", "");
Custom_formats["."]=SFormat("", "");
@ The existing |Detect a new text style| has hard-coded values:
@=
} else if(contents[index + 1] == '^' || contents[index + 1] == '.') {
ESectionType styleType = contents[index + 1] == '^' ? ESectionType.BOLD : ESectionType.PRE;
@ and our new version will detect a registered formatter and use that.
@=
} else if("" ~ contents[index + 1] in Custom_formats) {
ESectionType styleType = ESectionType.CUSTOM;
string customFormat = "" ~ contents[index + 1];
@ And note the format on the block of text.
@=
results ~= SBlock(styleType, lineNumber, textBlock, customFormat);
@ When styling the text, look up the formatter and apply it.
@