Hello all,
when converting HTML to XWiki 2.1 syntax, <code>...</code>
tags are ignored.
I was wondering why they are not converted to monospace formatting ##...##
,
like for example <sup>...</sup>
is converted to ^^...^^
.
Is there any specific reason or is it just not implemented?
On the other hand, converting from XWiki 2.1 to HTML will replace ##...##
with <span class="monospace">...</span>
, which does not really do anything if this class is not styled with CSS.
It’s mainly because it’s not implemented in the parser, and also a bit because there is no dedicated element in the XWiki DOM to semantically represent the concept which is supposed to be covered by the <code>
element (but I guess that indeed monospaced format block could be considered better than nothing from what I can see in <code>: The Inline Code element - HTML: HyperText Markup Language | MDN).
Don’t hesitate to propose a pull request for it. I assume the location where it would make the most sense is xwiki-rendering/xwiki-rendering-syntaxes/xwiki-rendering-syntax-xhtml5/src/main/java/org/xwiki/rendering/internal/parser/xhtml5/XHTML5Parser.java at master · xwiki/xwiki-rendering · GitHub (my understanding it that it does not exist in xhtml/1.0
specification, which is honestly another reason why it was not initially included in the parser).
I thought we were converting them to use the {{code}}
macro but it doesn’t seem to be the case (this is done in the markdown parser for example but it doesn’t seem we’re doing it in the HTML parsers).
We could do that while waiting for https://jira.xwiki.org/browse/XRENDERING-266
Note that monospace is not a good fit for <code>
IMO. Monospace is for <pre>
, not <code>
.
I don’t really agree here. You might want to take a look at https://developer.mozilla.org/en-US/docs/Web/HTML/Element/code: “By default, the content text is displayed using the user agent’s default monospace font.”. It’s really just that in a browser by default, apparently. Also, <pre>
is not really an inline element while <code>
always is.
Indeed, seems you’re right. PRE seems to be only used to preserve new lines when used around a code tag. So it would indeed be easy to at least use monospace, if we don’t want to use the code
macro, which is “optional” and thus not great to use in a parser. In addition, when rendered back, it would be transformed into a special comment (with the annotated html syntax).
So +1 to use monospace while waiting for Loading...
Feel free to create a jira @Nimra (another one ;))
I think <code>
is also valid in XHTML 1.0 as seen in XHTML 1.0: The Extensible HyperText Markup Language (Second Edition)
OK, not sure why I thought it had been introduced with HTML5. Then I guess the best location might be xwiki-rendering/xwiki-rendering-wikimodel/src/main/java/org/xwiki/rendering/wikimodel/xhtml/impl/XhtmlHandler.java at master · xwiki/xwiki-rendering · GitHub.