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 slide separator in case no separator is provided and heading indicates the new slide #9

Merged
merged 6 commits into from
Jul 25, 2024

Conversation

PrajwolAmatya
Copy link
Contributor

Description

In this PR, adds a new attribute value data-separator-by-heading to indicate whether heading represents the start of the new slide. In this case, no slide separator is required and the plugin will add default slide separator above the slide headings.

Usage

To use this feature, add the attribute data-separator-by-heading in the section tag as below:

<div class="reveal">
    <div class="slides">
        <section data-markdown="path/to/markdown/file" data-seperator-by-heading></section>
    </div>
</div>

And the markdown file can be simply provided as:

---
metadata_key1: metadata_value1
metadata_key2: metadata_value2
---
# Slide 1

# Slide 2

# Slide 3

@PrajwolAmatya PrajwolAmatya self-assigned this Jul 4, 2024
@PrajwolAmatya PrajwolAmatya marked this pull request as ready for review July 4, 2024 10:14
@PrajwolAmatya PrajwolAmatya force-pushed the add-separator branch 2 times, most recently from cda8d47 to 8a62791 Compare July 5, 2024 10:55
plugin/awesoMD/plugin.js Outdated Show resolved Hide resolved
plugin/awesoMD/plugin.js Outdated Show resolved Hide resolved
Copy link
Member

@individual-it individual-it left a comment

Choose a reason for hiding this comment

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

The description seems not to describe everything that happens in the PR, or is it because its mixed with #8 ?


// add slide separator in the case heading indicates the new slide
if (options.separateByHeading) {
options['slideSeparator'] = '---'
Copy link
Member

Choose a reason for hiding this comment

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

still, this is "hardcoded"
what will happen if the app options.separator is set to +++ but we add --- as a separator here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the apps options.separator doesn't store the separator value, instead it stores the regex pattern of the slide separator. The default regex pattern is stored as const DEFAULT_SLIDE_SEPARATOR = '\r?\n---\r?\n'. If other pattern is to use then it is defined by attribute data-separator in the index.html file as:
<section data-markdown="markdown/simplified.md" data-separator="\r?\n---\r?\n"></section>

The slide separator used in the markdown file and the pattern defined in data-separator should match. The plugin looks for the slide separator pattern and separates the slide. If different value is used for the slide separator in the markdown file then we should provide that regex pattern in data-separator attribute, and if this attribute is not specified in the section tag then the plugin will take the pattern specified in DEFAULT_SLIDE_SEPARATOR.

In our case, we do not provide slide separator in markdown file, so we somewhere need to specify the value of the slide separator. If we don't want to hard code here in the plugin, we can set this as default slide separator and specify the slide separator in index.html file as:
<section data-markdown="markdown/simplified.md" data-separator="\r?\n---\r?\n" data-separator-by-heading slide-separator="---"></section>
When there is data-separator-by-heading attribute, there should be slide-separator present in the section tag and matching regex pattern in data-separator attribute. With that we can skip the hard coding slide separator in the plugin.

Copy link
Member

Choose a reason for hiding this comment

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

OK, thank you for the explanation 👍
I now understand the challenge.
I rather would not introduce a new option. Maybe the easiest is to define that when data-separator-by-heading is used data-separator cannot be set to anything that is not default.
So then we can keep it hard-codded, but just need to have a check when options.separateByHeading is set whether options.separator === DEFAULT_SLIDE_SEPARATOR and if not show an error

const spySeparateInlineMetadataAndMarkdown = jest.fn(plugin().separateInlineMetadataAndMarkdown)
const [markdown, fm] = plugin().parseFrontMatter(markdownContent, {})

const slides = markdown.split(/^---\n/gm)
Copy link
Member

Choose a reason for hiding this comment

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

please create a test with an other separator also, see my comment above

const newMetadata = headingWithMetadataRegex.test(markdown)
yamlRegex.lastIndex = 0

if (options.separateByHeading) {
Copy link
Member

Choose a reason for hiding this comment

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

please add a test that checks if the behavior is correct when this value is set to true

tests/unit/testFiles/inlineMetadata.md Outdated Show resolved Hide resolved
@PrajwolAmatya
Copy link
Contributor Author

PrajwolAmatya commented Jul 15, 2024

The description seems not to describe everything that happens in the PR, or is it because its mixed with #8 ?

Yes, this PR is rebased with #8, that's why the description does not match. First I want to merge that PR and then this PR.

Copy link
Member

@individual-it individual-it left a comment

Choose a reason for hiding this comment

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

last commit should also have a test, rest looks good to me

}
}

if (animateLists === true) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (animateLists === true) {
if (animateLists) {

Copy link
Member

Choose a reason for hiding this comment

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

Is the type of animatedList ever checked? If not then I don't think this is good style, because this will be also true for these cases:

  • animateLists='false'
  • animatedList=2

Also how does this change relate to the topic of the PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are the codes that we copied from the main reveal.js plugin. The animateLists variable is true if defined otherwise it is undefined.
This is not actually related to this PR. Maybe the confusion came up because there's a lot of changes in the plugin.js file.
I will revert this change back, since it is the part of code that was copied from reveal.js plugin. 👍

@PrajwolAmatya PrajwolAmatya merged commit e13ee8a into main Jul 25, 2024
1 check passed
@PrajwolAmatya PrajwolAmatya deleted the add-separator branch July 25, 2024 09:23
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.

3 participants