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 Multi-line Dictionary Definition (<dd>) rows. #3129

Merged
merged 62 commits into from
Mar 14, 2024

Conversation

dbolack-ab
Copy link
Collaborator

@dbolack-ab dbolack-ab commented Nov 7, 2023

Expands the existing syntax to allow/expect the option of multiple definitions by adding any number of :: Definition to an a DT/DD set.

Solves #2340.

Final Syntax and Behavior

This has been updated to a multi-description ( DD ) mode that can take multi-line input. This mode expects the term on one line, the description(s) on lines after, then a blank line before a new term. Two blank lines terminate the list.

This cannot be mixed with the existing inline style definition lists.

Example:

Term 1
:: Definition 1
:: Definition 2
is on multiple lines

Term 2:
:: Definition 1


Test case Brew at: https://homebrewery.naturalcrit.com/share/h-sHSQsRyUlz

Expands the existing syntax to allow/expect the option of multiple
definitions by adding any number of ``` :: Definition``` to an a DT/DD
set.
Fixes syntax highlighting to account for multiple definitions on a
definition list.
@calculuschild
Copy link
Member

Before going further with this, I think we need to have a little more discussion about where this syntax would actually be used. As I mentioned in this comment #2340 (comment), there was a specific use case we identified for the single-line syntax we currently use. I don't think we have any use case identified for multiple <dd> entries yet. How should we render these? What CSS should go along with them? Does it do something that we already do just as well with plain paragraphs? I don't think any of that was settled in #2340.

As another note, this PR unfortunately breaks existing <dl> rendering by adding a \n

@calculuschild calculuschild added the 🔍 R1 - Reviewed - Needs Discussion 💬 PR not okayed yet; needs reevaluation or closure label Nov 10, 2023
@dbolack-ab
Copy link
Collaborator Author

dbolack-ab commented Nov 10, 2023

Before going further with this, I think we need to have a little more discussion about where this syntax would actually be used. As I mentioned in this comment #2340 (comment), there was a specific use case we identified for the single-line syntax we currently use. I don't think we have any use case identified for multiple <dd> entries yet. How should we render these? What CSS should go along with them? Does it do something that we already do just as well with plain paragraphs? I don't think any of that was settled in #2340.

As another note, this PR unfortunately breaks existing <dl> rendering by adding a \n

I'm not spotting this?

                return `<dl>${token.definitions.reduce((html, def)=>{
-                       return `${html}<dt>${this.parser.parseInline(def.dt)}</dt>`
-                                   + `<dd>${this.parser.parseInline(def.dd)}</dd>\n`;
+                       const dds = def.dd.map((s)=>`<dd>${this.parser.parseInline(s)}</dd>`).join('\n');
+                       return `${html}<dt>${this.parser.parseInline(def.dt)}</dt>
+                               ${dds}`;
                }, '')}</dl>`;

Do you mean the linebreak between the close of the <dt> and the open of the first <dd> ?

@calculuschild
Copy link
Member

Do you mean the linebreak between the close of the

and the open of the first
?

Yep. Try generating a monster stat block on this PR for example. We format the <dt> and <dd> to be on one line, but that \n breaks all the formatting.

image

@dbolack-ab
Copy link
Collaborator Author

Do you mean the linebreak between the close of the and the open of the first ?

Yep. Try generating a monster stat block on this PR for example. We format the <dt> and <dd> to be on one line, but that \n breaks all the formatting.

image

Weird. That is not what I remember to be the correct behavior for a DD/DT pair but it's been a spell. :)

Remove the linbreak between the </dt> and the first <dd>
@dbolack-ab
Copy link
Collaborator Author

Do you mean the linebreak between the close of the and the open of the first ?

Yep. Try generating a monster stat block on this PR for example. We format the <dt> and <dd> to be on one line, but that \n breaks all the formatting.
image

Weird. That is not what I remember to be the correct behavior for a DD/DT pair but it's been a spell. :)

I think this is good now.

FixedDD

Updated to allow multiple definition terms and definitions per term

<Term>::<definition>
<Term>::<definition1>::<definition2>
::<definition3>

```
**Example** ::
::V3 uses HTML *definition lists* to create "lists" with hanging indents.
::Three
I'm a term::Four

**<u>Hello</u>**::I\'m a different
::List
:
```
@calculuschild
Copy link
Member

This looks good! I'm just going to go through and see if the logic can be shortened up at all, then merge.

@dbolack-ab
Copy link
Collaborator Author

@calculuschild Is the multiline regression from your work or did I miss it?

@calculuschild
Copy link
Member

calculuschild commented Mar 10, 2024

@calculuschild Is the multiline regression from your work or did I miss it?

It's just a new test I added today for an edge case we missed.

Pretty sure I know where the fix is though. I'm planning to merge it in just a bit.

@dbolack-ab
Copy link
Collaborator Author

@calculuschild Is the multiline regression from your work or did I miss it?

It's just a new test I added today for an edge case we missed.

Pretty sure I know where the fix is though. I'm planning to merge it in just a bit.

Okay. The fail I'm seeing is indeed a fail that worked at last I remember.

      <dl><dt>Term 1</dt>
    - <dd>Definition 1 and more and more</dd>
    + <dd>Definition 1</dd>
    + <dt>and more and more</dt>
      <dd>Definition 2</dd>
      <dd>Definition 3</dd></dl>

@calculuschild
Copy link
Member

calculuschild commented Mar 10, 2024

No, it was broken before. It comes from this test which was written with bad syntax:

Term 1
::Definition 1
Term 2          <- Pandoc-style lists need a blank line between terms.
::Definition 1

This should output:

<dl>
<dt>Term 1</dt>
<dd>Definition 1 Term 2</dd> ("Term 2" is part of dd1 multiline)
<dd>Definition 1</dd>
</dl>

I added an extra newline between the Terms to correct that test, then added this new test which just changes Term 2 to more and more and added one more Definition 3 for good measure.

@dbolack-ab
Copy link
Collaborator Author

No, it was broken before. It comes from this test which was written with bad syntax:

Term 1
::Definition 1
Term 2          <- Pandoc-style lists need a blank line between terms.
::Definition 1

This should output:

<dl>
<dt>Term 1</dt>
<dd>Definition 1 Term 2</dd> ("Term 2" is part of dd1 multiline)
<dd>Definition 1</dd>
</dl>

I added an extra newline between the Terms to correct that test, then added this new test which just changes Term 2 to more and more and added one more Definition 3 for good measure.

Yeah, that seems right.

Split into two extensions as single-line and multiline are different syntaxes. Simplified a lot of logic and probably cleaner as their own NPM packages (eventually).
@calculuschild calculuschild temporarily deployed to homebrewery-pr-3129 March 14, 2024 04:03 Inactive
@calculuschild calculuschild merged commit e412a37 into naturalcrit:master Mar 14, 2024
2 checks passed
@calculuschild
Copy link
Member

Thanks @dbolack-ab ! 💯 ⭐ 🎉

I found more edge cases, but it turns out just splitting each syntax into its own extension solved everything. And then I realized that let me simplify a lot too as a bonus.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants