Skip to content
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

💬 Add epigraph, pull-quote and blockquote directive #961

Merged
merged 36 commits into from
Mar 13, 2024

Conversation

agoose77
Copy link
Collaborator

@agoose77 agoose77 commented Mar 7, 2024

The intentions of this PR are twofold:

  1. Provide a learning curve for authoring directives in MyST
  2. Implement support for epigraphs and pull-quotes

I'll try and document my thought processes as we go.

The merge order should be

  1. ENH: add blockquote to supported container contents myst-spec#64
  2. 💬 Add epigraph, pull-quote and blockquote directive #961
  3. 💬 Add style for pull-quotes myst-theme#328

@agoose77
Copy link
Collaborator Author

agoose77 commented Mar 7, 2024

Here's what I wrote in Discord about my initial thoughts:

I'm looking to implement support for epigraphs and pull-quotes. Adding a new quote directive (pull-quote) is fairly easy, but adding a new epigraph directive throws up some questions for me:

  1. We use transforms to apply custom syntax rules, e.g. GFM admonitions (blockquote -> admonition). Is this "safe" w.r.t third-party mdast utilities? i.e., if a third-party tool expects the non-MyST mdast, does the presence of our nodes in the tree in unexpected places cause issues? I assume that perhaps MDAST is built such that one can extend it, so these tools should ignore unknown content?
  2. For nodes with well-constrained children, should we lift the child into an attribute of the parent? e.g. for epigraph, there's an attribution. Sphinx seems to leave that as a node-type, added to children. Should we think about doing the same, or create a new epigraph MDAST node that has an attribution field? My feeling is strongly the former; we want to avoid duplicating existing MDAST nodes in favour of "extending" them through children. I also assume we shouldn't generally add attributes to existing MDAST nodes defined in https://github.com/syntax-tree/

@agoose77
Copy link
Collaborator Author

agoose77 commented Mar 7, 2024

I then noticed some prior art for epigraphs, in tex-to-myst. So, it looks like we're re-using the caption node instead of attribution node. Hmm, OK, let's try that (see e3e8f30)

@agoose77
Copy link
Collaborator Author

agoose77 commented Mar 7, 2024

It looks like this falls foul of another transform,

`container of kind ${container.kind} contains no valid content${
, which seems to assume a closed set of container node types. It looks like the tex-to-myst epigraph conversion isn't anticipated here. I wonder why, I assume that this transform would apply after tex-to-myst (e.g. via a raw) directive.

@agoose77
Copy link
Collaborator Author

agoose77 commented Mar 7, 2024

The next step from here probably depends upon whether we want blockquote et al. to support attribution (captions). If we do (which feels like a commonmark regression), we can just make epigraph a synonym of blockquote, and implement the captioning using a transform.

If not, then we need to adjust the container transform.

@agoose77
Copy link
Collaborator Author

agoose77 commented Mar 11, 2024

I think the simplest solution is to make all quotes support captions, which is what 87e4189 does. Now, pull-quotes and epigraphs can be styled separately should we wish for them to be.

@agoose77 agoose77 marked this pull request as ready for review March 11, 2024 15:44
@agoose77 agoose77 requested a review from rowanc1 March 11, 2024 15:44
Copy link
Member

@rowanc1 rowanc1 left a comment

Choose a reason for hiding this comment

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

Looking good. Have some comments about the change in functionality (I think we should keep it!), adding more tests, changesets, and some files that have been changed and probably don't need to be anymore (package.json, spec-ext).

On the changed functionality: This might have been hashed out in discord/convos, but I am a fan of the list item transform which this PR is planning to remove. One reason I like it is that the attribution doesn't require a new line, and in both cases we are interpreting the final markup using this transform, in one case to turn a paragraph into an attribution caption and in the other to turn a single list item into an attribution. I don't really see the difference, and it is nice that we can do this:

> We know what we are, but know not what we may be.
> - Hamlet act 4, Scene 5

Rather than:

> We know what we are, but know not what we may be.
>
> -- Hamlet act 4, Scene 5

I foresee challenges when people forget that there needs to be an extra new line, which means there is only one paragraph. Some of that can be addressed potentially if we take over the body content in the parsing of the epigraph/pull-quote directives (where we are explicitly expecting an attribution, and can change the parsing).

Regardless of the choice, this PR should update the docs here:

https://github.com/executablebooks/mystjs/blob/main/docs/typography.md#L112

Testing

I would also love to see a few more tests around the regexp, expanding it to endash, I think there is a bug when it isn't the start of the line (e.g. blah --- attribtuion), and ensuring we return false if there is no actual attribution. It would also be good to add some tests for the directive parsing specifically.

There should also be some e2e test (or at least exploratory conformation) that this doesn't clash with the smart typography, which turns -- into (endash), in which case, expanding the regexp into --- \u2014- meaning three dashes will always fail currently.

The directive docs/references should also be added to include the two new directives:

https://github.com/executablebooks/mystjs/blob/main/docs/directives.md#L2

Before merge, should add changesets!

package-lock.json Outdated Show resolved Hide resolved
packages/myst-spec-ext/src/types.ts Outdated Show resolved Hide resolved
packages/myst-transforms/src/blockquote.ts Outdated Show resolved Hide resolved
packages/myst-transforms/src/blockquote.ts Outdated Show resolved Hide resolved
packages/myst-directives/src/quote.ts Outdated Show resolved Hide resolved
@rowanc1
Copy link
Member

rowanc1 commented Mar 11, 2024

Somewhere along the way we have lost adding the class quote on the figure[kind=quote] node. Adding this back in makes the CSS work again:

image

I think this actually might be on the theme and putting the figure.kind in at the start of the classes. The bug was introduced here:

executablebooks/myst-theme#277

@agoose77
Copy link
Collaborator Author

On the changed functionality: This might have been hashed out in discord/convos, but I am a fan of the list item transform which this PR is planning to remove. One reason I like it is that the attribution doesn't require a new line, and in both cases we are interpreting the final markup using this transform, in one case to turn a paragraph into an attribution caption and in the other to turn a single list item into an attribution. I don't really see the difference, and it is nice that we can do this:

I see the convenience of using - attribution syntax for attributions. If it were just a matter of syntax, I'd be easily won in either direction. However, there are three factors that favour the -- variant for me:1

  • Existing implementation: Sphinx, Asciidoctor(? https://github.com/arquillian/continuous-enterprise-development/blob/master/ch01.asciidoc), and others seem to use emdash/--. We are currently explicitly deviating from that
  • Convention: non-parsed Markdown seems to reflect the common usage in written prose that prefers -- or emdash
  • Fragility: it's much more common (assertion, no data) to see list items in quotes than -- / as trailing items. We would break these usages. Though, single list items are probably not too common either.

Some of that can be addressed potentially if we take over the body content in the parsing of the epigraph/pull-quote directives (where we are explicitly expecting an attribution, and can change the parsing).

I had this thought too. We could also introduce an explicit role, e.g.

> We know what we are, but know not what we may be.
> {attrib}`Hamlet act 4, Scene 5`

I'm not saying that I love that, just that it's a member of the phase space ;)

Regardless of the choice, this PR should update the docs here:

Yep, TODO.

Footnotes

  1. I had an additional point in mind here, but stepped away from the keyboard and promptly forgot it. So, maybe there are four points!

Copy link
Member

@rowanc1 rowanc1 left a comment

Choose a reason for hiding this comment

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

I think only major comment left is picking up the options in the directives (and adding a test!).

Before merge:

  • We should also finalize/update the docs in typography.md.
  • changeset!

packages/myst-directives/src/quote.ts Outdated Show resolved Hide resolved
packages/myst-transforms/src/blockquote.ts Outdated Show resolved Hide resolved
packages/myst-transforms/src/blockquote.ts Outdated Show resolved Hide resolved
@rowanc1
Copy link
Member

rowanc1 commented Mar 12, 2024

On the functionality change, thanks for explaining your thinking - happy on my side to be taken in this direction. :)

We should make an explicit note in the docs updates to remember to add a newline.

Note that updating the docs will take a release, theme release, and then website release to consume the theme (in the live example).

@rowanc1 rowanc1 changed the title ENH: add epigraph directive ENH: add epigraph and pull-quote directive Mar 12, 2024
@agoose77 agoose77 force-pushed the agoose77/feat-add-epigraph-et-al branch from c8d2101 to 642671b Compare March 13, 2024 11:27
@agoose77 agoose77 requested a review from rowanc1 March 13, 2024 11:44
Copy link
Member

@rowanc1 rowanc1 left a comment

Choose a reason for hiding this comment

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

Nice to see the consolidation into one directive. What do you think of naming this blockquote (no dash?). Can alias as well? Maybe I am too used to reading html source.

import classNames from 'classnames';

export const blockQuoteDirective: DirectiveSpec = {
name: 'block-quote',
Copy link
Member

Choose a reason for hiding this comment

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

I think this should be blockquote (maybe aliased to block-quote?).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm. I'm on the fence. I like that it reflects symmetry with pull-quote, but of course the internal AST node is blockquote. You make the call!

class: classNames({ [className]: className, [data.name]: data.name !== 'block-quote' }),
children: [
{
// @ts-expect-error: myst-spec needs updating to support blockquote
Copy link
Member

Choose a reason for hiding this comment

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

Is this handled in the myst-spec updates?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No! Actually now I understand where my confusion came from. Let me fix that up.

packages/myst-directives/src/blockquote.ts Outdated Show resolved Hide resolved
packages/myst-transforms/src/blockquote.ts Outdated Show resolved Hide resolved
docs/typography.md Outdated Show resolved Hide resolved
.changeset/seven-roses-cough.md Outdated Show resolved Hide resolved
docs/directives.md Outdated Show resolved Hide resolved
@agoose77
Copy link
Collaborator Author

@rowanc1 this is ready for handover!

@rowanc1 rowanc1 force-pushed the agoose77/feat-add-epigraph-et-al branch from 46e291c to 65f2ae9 Compare March 13, 2024 15:28
@rowanc1 rowanc1 changed the title ENH: add epigraph and pull-quote directive 💬 Add epigraph, pull-quote and blockquote directive Mar 13, 2024
@rowanc1 rowanc1 merged commit 42af380 into main Mar 13, 2024
4 checks passed
@rowanc1 rowanc1 deleted the agoose77/feat-add-epigraph-et-al branch March 13, 2024 15:33
@agoose77
Copy link
Collaborator Author

🎆

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.

None yet

2 participants