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

Attributes in markdown #640

Merged
merged 14 commits into from
Nov 6, 2013
Merged

Attributes in markdown #640

merged 14 commits into from
Nov 6, 2013

Conversation

VonC
Copy link
Contributor

@VonC VonC commented Oct 11, 2013

Slide attributes in Markdown

Allow an external Markdown file to set attributes for each slide

(replace #639, because the pull request is now rebased on dev, not master):

<div class="slides">
      <section  data-markdown="training.md" 
                data-separator="^\n\n\n" 
                data-vertical="^\n\n" 
                data-notes="^Note:" 
                data-attributes="^\s*?--\s(.*?)$"        <=========
                data-charset="utf-8">
      </section>
      </div> <!-- slides -->

For example, that slide will set an id, transition and color:

## Plan:
-- id="plan" data-transition="zoom" data-background="#0f0f0f"

My plan is....

The slide attributes themselves are removed from the final markdown content, and not visible in the resulting html slide.

Incidentally, that should also solve #430 (Markdown Support for internal links);
Another slide can now refers to "plan" with:

[Link to Plan](#/plan)

@VonC
Copy link
Contributor Author

VonC commented Oct 28, 2013

@hakimel I have rebased this pull request on top of #677 that you just merged into dev.

I have also restored the initial pattern for attributes in elements {. xxx="yyy"}, and make sure the unit-test do test the ability to define a different pattern.
That means that c472ca3 fixes 080ae79.

You will find the same idea in the test/test-markdown-attributes.html unit test file, where data-attributes defines a different pattern than the one used by default.

@hakimel
Copy link
Owner

hakimel commented Oct 29, 2013

Nice. Can you also remove the debug code (console logs) and add an example to the readme that uses the default slide attribute separator?

@VonC
Copy link
Contributor Author

VonC commented Oct 29, 2013

@hakimel

Can you also remove the debug code (console logs) and add an example to the readme that uses the default slide attribute separator?

All done, and pushed, based on your latest dev branch.

@hakimel
Copy link
Owner

hakimel commented Oct 29, 2013

Thanks man! At work now but will merge this in shortly.

By default, look for <!-- slide-attributes: xxxx -->.
Whatever 'xxx' is will be added to the section attributes.

You can define your own pattern with 'data-attributes'.
For instance 'data-attributes="^\s*?-- (.*?)$"':
that will be added to the options.

The 'attributes' section is removed from the content of the slide,
so the final markdown doesn't reflect them.
That also means you can add those attributes *anywhere* in the slide

But that allows for *any* attribute to be added for a specifc slide,
like:

- id="plan", for allowing internal link (issue hakimel#430)
- data-background="#ff0000"
- data-transition="fade"

You list those attributes on a single line, like

- (default):
` <!-- id="plan" data-background="#ff0000" -->`
- or, with an alternative data-attributes pattern:
` -- id="plan" data-background="#ff0000"`

Again, that line is remove from the final content.
The first slide of a vertical stack see some data attributes ignored.

Mainly the data-transition one.

Repeat all data-attributes on the wrapping section element.

Ignore any other attributes (like 'id="xxx"'), in order to not
mess with internal links (by repeating twice an id).
It is important that test/test-element-attributes-markdown.html do test
the ability for the user to define its own pattern.
It should be `{. xxxx=yyy }`, not `{_ xxxx=yyy }`.
Only test/test-element-attributes-markdown.html were using `{_`,
simply in order to test the ability, for the user, to define a _different_ pattern.
@VonC
Copy link
Contributor Author

VonC commented Nov 5, 2013

@hakimel I have rebased the attributes_in_markdown branch on top of your latest dev branch (7da98d8): the tests are still good.

@hakimel
Copy link
Owner

hakimel commented Nov 5, 2013

I've already pulled this into my local branch but haven't pushed it yet since I'm running into issues. Attributes are working in test but the following simple single-slide test doesn't work:

<section data-markdown>
    <script type="text/template">
        <!-- slide-attributes: data-background="#ff0000" -->
        ## Hello world
    </script>
</section>

Also what do you think about bringing this and the element attribute syntax closer together? I'd like there to be some theme to this since there's getting to be a lot of different separator expressions.

@VonC
Copy link
Contributor Author

VonC commented Nov 5, 2013

@hakimel "element syntax selection"? Are you talking about my previous markdown patch #677?

It yes, those are two different syntaxes for two different use cases. I'll prefer to see them separate. The default patterns are important (for classes in markdown-generated elements, it is an html comment, in order for those classes to not be displayed in an html preview, when using a markdown editor like https://stackedit.io/).

First, I'll include your case in the slide attributes unit tests, and debug that.

@hakimel
Copy link
Owner

hakimel commented Nov 5, 2013

That's meant to be element attribute syntax. Okay the usefulness of HTML comment syntax makes sense, so how about we define element attributes in the same way?

## Hello world <!-- element-attributes: class="fragment" -->

@VonC
Copy link
Contributor Author

VonC commented Nov 6, 2013

@hakimel Can you try again you test case?

<section data-markdown>
    <script type="text/template">
        <!-- slide-attributes: data-background="#ff0000" -->
        ## Hello world
    </script>
</section>

It should work now just fine. And the test cases have been updated to test just that scenario.

Once you have merge and published that on the branch hakimel/reveal.js@dev, I'll open a new issue/pull request to discuss how to merge markdown element attributes #677, and slide attributes (this pull request #640).

@hakimel hakimel merged commit 4b0fe47 into hakimel:dev Nov 6, 2013
@hakimel
Copy link
Owner

hakimel commented Nov 6, 2013

Thanks for fixing that. I've merged this in.

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.

2 participants