Skip to content

Conversation

@adamdruppe
Copy link
Contributor

The existing $(D) macro does PSYMBOL highlighting, so change the highlightCode call to match that. std.datetime also revealed another off-by-one bug with embedded html so the i-- takes care of that. Test amended with these cases.

@CyberShadow
Copy link
Member

Does this fix the true / <b>true</b> weirdness too?

@adamdruppe
Copy link
Contributor Author

No, that stays the same, and I think it should because the reason it gets bold is ddoc is seeing it as plain text. Code inside backticks is not interpreted as plain text anymore - it is minimally-highlighted code.

There's a very important difference there: <html> works, whereas plain text html is skipped and output in the final document unchanged. This whole thing is useless to me if I can't write literal html examples in the ddoc, so I won't change that.

The way this works is that there's nothing magical about $(D ...) (nor any other macro btw, all macros in ddoc are done by a separate macro.c file which knows nothing about D and nothing about ddoc context).

ddoc ALWAYS bolds the word true when it appears in plain text. Since the macro is non-magic, it counts as plain text, and gets bolded. (specifically, it wraps it in $(DDOC_KEYWORD) ... which is distinct from $(D_KEYWORD), which it uses in the code blocks).

Line 2096 of doc.c has the isKeyword function and you can see it only does it for true, false, and null. It is only called in one place: the default case of highlightText. Code highlighting is done by checking the keywords against dmd's lexer (line 2674 - tok.isKeyword() instead of isKeyword(), remember, no UFCS in c++!), but that's only triggered in side the --- example --- sections - the highlightCode2 function.

(which my first draft used and got keyword highlighting, but that wasn't universally liked)

/++
`true`
$(D true)
true
---
true
---

Macros:
D=<code>$0</code>
DDOC_BACKQUOTED = $(D $0)

+/

Makes:

<code>true</code> // quoted code, calls highlightCode() (called from highlightText)
<code><b>true</b></code> // macro, inherits <b> from highlightText
<b>true</b> // plain text, from highlightText
<pre class="d_code"><font color=blue>true</font> // block code, from highlightCode2 (which is called from highlightText)
</pre>

So, if you want true highlighted as a DDOC_KEYWORD, do NOT wrap it in the backquotes so it is treated as plain text by ddoc - whether passed to a macro or not is irrelevant. Or since the phobos seems to highlight inline code as bold anyway, it can stay the same and have no visual difference.

src/doc.c Outdated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks misaligned

@adamdruppe
Copy link
Contributor Author

OOps, a couple tabs slipped in there. Fixed.

@kuettler
Copy link

LGTM, if I might say so. Any reason not to merge it?

@quickfur
Copy link
Member

LGTM

@andralex
Copy link
Member

Auto-merge toggled on

@quickfur
Copy link
Member

Hooray!

andralex added a commit that referenced this pull request Jan 25, 2015
Changes to better match $(D ...) in Phobos and bug fix
@andralex andralex merged commit 8626695 into dlang:master Jan 25, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants