Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@tarleb
Copy link
Collaborator

@tarleb tarleb commented May 21, 2021

Spans with "smallcaps" as the first class are converted to SmallCaps
elements. While previously no other classes or attributes were allowed,
additional classes, attributes, and an identifier are not permitted and
kept in a SmallCaps wrapping Span element.

The same change is applied to underline spans, where the first class
must be either "ul" or "underline".

Closes: #4102

@tarleb
Copy link
Collaborator Author

tarleb commented May 21, 2021

I'm having second thoughts about this change, so I'm putting it here as a PR.

@tarleb tarleb force-pushed the allow-additional-attr-in-special-spans branch from 36872a4 to e0e7eb9 Compare May 21, 2021 15:47
@jgm
Copy link
Owner

jgm commented May 21, 2021

I think this makes sense, but why require that the special class be the first one?
(I guess it makes pattern-matching faster, but probably only slightly.)

@tarleb
Copy link
Collaborator Author

tarleb commented May 21, 2021

My thought here was that it might give the best balance between new functionality and unintended conversions. I wouldn't be too surprised to see ul be used as a class in other contexts, and the proposed solution still allows to do so.

@tarleb tarleb force-pushed the allow-additional-attr-in-special-spans branch from e0e7eb9 to 455e36c Compare May 27, 2021 13:32
@tarleb
Copy link
Collaborator Author

tarleb commented May 27, 2021

I've added a second commit (intended to be squashed) that removes the limitation of expecting the special class as the first, allowing it to occur in any position.

@tarleb tarleb force-pushed the allow-additional-attr-in-special-spans branch from 455e36c to 78c9bf1 Compare May 27, 2021 15:40
@jgm
Copy link
Owner

jgm commented May 27, 2021

I really don't know what's best here. Your concern about people wanting to use a span with class ul and not wanting that to be parsed as an Underline element gives me pause. On the other hand, the convention that the special class must occur first seems a bit too "magic" and might surprise people. And even with this, we might get some people who want just a span with class ul.

@tarleb
Copy link
Collaborator Author

tarleb commented May 27, 2021

Maybe we should just keep the current behavior and document the behavior as intentional? Or, but that's a bit of a stretch, we could hide the new behavior behind the attributes extension.

I note that neither the .underline nor .ul class are documented yet in the manual; the changelog only states "Support new Underline element in readers and writers". Removing support for .ul should not support too many problems.

@jgm
Copy link
Owner

jgm commented May 27, 2021

I don't think I'd want to remove the current behavior for ul, if that's what you meant. That would cause existing documents to break. It should be documented, though.

@jgm
Copy link
Owner

jgm commented Aug 16, 2021

Note that in a recent commit 649133f .ul and .underline were documented.

Maybe I'll take out the documentation for .ul, just in case we decide to remove it.

jgm added a commit that referenced this pull request Aug 16, 2021
See #7307.  Motivation: there is talk of removing this.
@hftf
Copy link
Contributor

hftf commented Sep 18, 2021

Note that in a recent commit 649133f .ul and .underline were documented.

Maybe I'll take out the documentation for .ul, just in case we decide to remove it.

I believe the Pandoc-flavored Markdown Writer still outputs [a]{.ul} from the input [Underline [Str "a"]], doesn't it?

inlineToMarkdown opts (Underline lst) = do
variant <- asks envVariant
contents <- inlineListToMarkdown opts lst
case variant of
PlainText -> return contents
_ | isEnabled Ext_bracketed_spans opts ->
return $ "[" <> contents <> "]" <> "{.ul}"
| isEnabled Ext_native_spans opts ->
return $ tagWithAttrs "span" ("", ["underline"], [])
<> contents
<> literal "</span>"
| isEnabled Ext_raw_html opts ->
return $ "<u>" <> contents <> "</u>"
| otherwise -> inlineToMarkdown opts (Emph lst)

(Speaking of the inconsistent output of Underline between Pandoc-flavored Markdown and the other Markdown flavors, this could be a good opportunity to decide/discuss whether "raw HTML" like <u> belongs in Pandoc-flavored Markdown output, even with bracketed_spans or native_spans enabled. See also #5825 (comment); I'll try to get that new issue filed soon.)

@jgm
Copy link
Owner

jgm commented Sep 18, 2021

So, the suggestion is to parse <u>...</u> as a native Underline element, and to generate it from an Underline element?
That does have a certain attraction. On the other hand, it isn't really consistent with how other raw HTML bits are treated. (<em>..</em> isn't parsed as Emphasis, for example).

@tarleb tarleb force-pushed the allow-additional-attr-in-special-spans branch 3 times, most recently from 9f1621c to 9619f6b Compare July 26, 2022 14:26
@tarleb
Copy link
Collaborator Author

tarleb commented Jul 26, 2022

The second commit in this PR removes the limitation of the special class (like smallcaps) having to be the first class, making it possible to use markup like [Populus Romanus]{.foo .smallcaps lang="latin"}.

@tarleb tarleb force-pushed the allow-additional-attr-in-special-spans branch from 9619f6b to 32f66cb Compare July 26, 2022 15:21
Comment on lines 1822 to 1829
return $ case smallCapsAttr attr of
Just ("", [], []) -> B.smallcaps <$> lab
Just scAttr -> B.spanWith scAttr . B.smallcaps <$> lab
Nothing -> case underlineAttr attr of
Just ("", [], []) -> B.underline <$> lab
Just ulAttr -> B.spanWith ulAttr . B.underline <$> lab
Nothing -> B.spanWith attr <$> lab

Copy link
Owner

Choose a reason for hiding this comment

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

Maybe, to be consistent with the recent change to the HTML writer, we should allow [test]{.underline .smallcaps} to turn into Underline [SmallCaps [Str "test"]]? Not sure, what do you think?

Copy link
Owner

Choose a reason for hiding this comment

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

This could be done fairly elegantly with a fold over the classes, similarly to what I did in the HTML writer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nice! Done.

tarleb added 2 commits August 1, 2022 09:48
Spans with "smallcaps" as the first class are converted to *SmallCaps*
elements. While previously no other classes or attributes were allowed,
additional classes, attributes, and an identifier are not permitted and
kept in a *SmallCaps* wrapping *Span* element.

The same change is applied to underline spans, where the first class
must be either "ul" or "underline".

Closes: jgm#4102
@tarleb tarleb force-pushed the allow-additional-attr-in-special-spans branch from 32f66cb to 40a8418 Compare August 1, 2022 09:39
@jgm jgm merged commit 7a4afce into jgm:master Aug 1, 2022
@tarleb tarleb deleted the allow-additional-attr-in-special-spans branch August 1, 2022 18:29
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.

Small caps combined with language

3 participants