-
Notifications
You must be signed in to change notification settings - Fork 270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
content: Handle code block spans with multiple CSS classes #1021
content: Handle code block spans with multiple CSS classes #1021
Conversation
@@ -1023,17 +1023,28 @@ class _ZulipContentParser { | |||
span = CodeBlockSpanNode(text: text, type: CodeBlockSpanType.text); | |||
|
|||
case dom.Element(localName: 'span', :final text, :final className): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can use dom.Element.classes
here, so we don't need to call .split(' ')
ourselves later
e37129c
to
cafabca
Compare
Thanks for the review @PIG208! Pushed a new revision, PTAL :) |
LGTM! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @rajveermalviya for taking care of this, and @PIG208 for the previous review!
Generally this looks great. Small comments below, most of them nits.
lib/model/content.dart
Outdated
final CodeBlockSpanType type = codeBlockSpanTypeFromClassName(className); | ||
switch (type) { | ||
case CodeBlockSpanType.unknown: | ||
case dom.Element(localName: 'span', :final text, :final classes): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the parser we should stick to className
, avoiding classes
🙂 — see #497.
lib/model/content.dart
Outdated
final spanType = | ||
classes | ||
.map(codeBlockSpanTypeFromClassName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: tighten formatting by putting part of the initializer on the first line, after the =
lib/model/content.dart
Outdated
// The general form for Pygments nodes with multiple classes observed | ||
// are, that the first class is the standard token class and trailing | ||
// tokens are non-standard tokens. Zulip web client only styles the | ||
// standard tokens classes. Same is done here, only standard token | ||
// class names are emitted. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// The general form for Pygments nodes with multiple classes observed | |
// are, that the first class is the standard token class and trailing | |
// tokens are non-standard tokens. Zulip web client only styles the | |
// standard tokens classes. Same is done here, only standard token | |
// class names are emitted. | |
// Empirically, when a Pygments node has multiple classes, the first | |
// class names a standard token type and the rest are for non-standard | |
// token types specific to the language. Zulip web only styles the | |
// standard token classes and ignores the others, so we do the same. |
The "are emitted" confused me: we don't emit any class names here, right? We consume class names, and may emit a CodeBlockSpanType value.
test/model/content_test.dart
Outdated
'<div class="codehilite" data-code-language="YAML">' | ||
'<pre><span></span><code><span class="p p-Indicator">-</span>' | ||
'<span class="w"> </span>' | ||
'<span class="l l-Scalar l-Scalar-Plain">item</span>\n' | ||
'</code></pre></div>', [ | ||
CodeBlockNode([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super nit: indent the string continuations deeper so they don't look like part of the same series as the list element below
'<div class="codehilite" data-code-language="YAML">' | |
'<pre><span></span><code><span class="p p-Indicator">-</span>' | |
'<span class="w"> </span>' | |
'<span class="l l-Scalar l-Scalar-Plain">item</span>\n' | |
'</code></pre></div>', [ | |
CodeBlockNode([ | |
'<div class="codehilite" data-code-language="YAML">' | |
'<pre><span></span><code><span class="p p-Indicator">-</span>' | |
'<span class="w"> </span>' | |
'<span class="l l-Scalar l-Scalar-Plain">item</span>\n' | |
'</code></pre></div>', [ | |
CodeBlockNode([ |
This is similar to what we do with if
conditions. You can also see it in action on the similar examples codeBlockHighlightedShort and codeBlockHighlightedMultiline above.
test/model/content_test.dart
Outdated
@@ -395,6 +395,23 @@ class ContentExample { | |||
ParagraphNode(links: null, nodes: [TextNode("some content")]), | |||
]); | |||
|
|||
static const codeBlockNodesWithMultipleClasses = ContentExample( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: put this just after the two codeBlockHighlighted…
examples, so it's not separated from them by all the unimplemented code-block examples
cafabca
to
4a70436
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the revision! Looks good, with just one comment below on something I missed earlier.
test/model/content_test.dart
Outdated
static const codeBlockNodesWithMultipleClasses = ContentExample( | ||
'code block nodes with multiple class names', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rereading, I realized this name is misleading: "code block node" should correspond CodeBlockNode
, since we have such an identifier; but the HTML element that corresponds to one of those is the whole div.codehilite
. The things that have multiple classes are the span
great-grandchildren of that, which correspond to CodeBlockSpanNode
.
I think "code block span" is a fine term for these.
So that applies to this example's name and description, and to the commit message.
4a70436
to
4224f4b
Compare
Thanks for the review @gnprice. Revision pushed. |
Thanks! All looks good — merging. |
4224f4b
to
e3d5471
Compare
Fixes: #933