Skip to content

Add the ability to specify options on the demo page as JSON - #1357

Merged
styfle merged 8 commits into
markedjs:masterfrom
aprotim:demo_options
Oct 19, 2018
Merged

Add the ability to specify options on the demo page as JSON#1357
styfle merged 8 commits into
markedjs:masterfrom
aprotim:demo_options

Conversation

@aprotim

Copy link
Copy Markdown
Contributor

Description

Create a details toggle that hides a textarea into which a user can type a JSON-formatted options object.

(For some reason, I can't seem to get the textarea inside a details tag to match the width of the other textareas. After staring at the CSS and banging my head against it, I figured I'd let other people look at it, decide if it was important, and if it was, how to fix it.)

screenshot from 2018-10-17 01-27-32

Contributor

  • Test(s) exist to ensure functionality and minimize regression (if no tests added, list tests covering this PR); or,
  • no tests required for this PR.
  • If submitting new feature, it has been documented in the appropriate places.

Committer

In most cases, this should be a different person than the contributor.

  • Draft GitHub release notes have been updated.
  • CI is green (no forced merge required).
  • Merge PR

@UziTech

Copy link
Copy Markdown
Member

I like being able to add the options but could we move it to the right list

image

@aprotim

aprotim commented Oct 18, 2018

Copy link
Copy Markdown
ContributorAuthor

I can do that, although right now all the things on the right are output/read-only, while the left side is input. What if instead of the details toggle, I added a similar dropdown on the input side? (Example of what it looks like forthcoming.)

@aprotim

aprotim commented Oct 18, 2018

Copy link
Copy Markdown
ContributorAuthor

How about this change? Now all input is on the left, all output is on the right, and both have parallel type selectors.

@aprotim

Copy link
Copy Markdown
ContributorAuthor

(FWIW, you can look at the live version at https://aprotim.github.io/marked/demo/)

@styflestyfle added the category: docs Documentation changes label Oct 18, 2018
@styfle

Copy link
Copy Markdown
Member

This is awesome!

When the page loads the first time and there are no options in the query string, can you do $optionsElem.value = JSON.stringify(marked.getDefaults(), null, ' ');

This will give people an idea of what options are available 👍

Per @styfle's suggestion, setting the options element's contents to the defaults on load.
@aprotim

Copy link
Copy Markdown
ContributorAuthor

When the page loads the first time and there are no options in the query string, can you do $optionsElem.value = JSON.stringify(marked.getDefaults(), null, ' ');

Done!

@UziTech

Copy link
Copy Markdown
Member

@aprotim looks like your demo page has an error

this.renderer.text is not a function

seems to be because the options are duplicated in the "renderer" option

...
"renderer": {
"options": {
"baseUrl": null,
"breaks": false,
"gfm": true,
"headerIds": true,
"headerPrefix": "",
"highlight": null,
"langPrefix": "language-",
"mangle": true,
"pedantic": false,
"renderer": {},
"sanitize": false,
"sanitizer": null,
"silent": false,
"smartLists": false,
"smartypants": false,
"tables": true,
"xhtml": false
}
},
...

@aprotim

Copy link
Copy Markdown
ContributorAuthor

Ah, yeah. This is a problem with the roundtrip through JSON, when the default value for "renderer" is a complex object, not a dumb data object. I can either remove renderer from the object before stringifying, or I can set the default options text to be some manually-curated subset... let me tinker with it for a sec.

@aprotim

Copy link
Copy Markdown
ContributorAuthor

Ok, now we filter any complex objects (or at least any objects whose prototype is different than Object's) out when we stringify. Seems to have cleared up the problem.

@styflestyfle left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a much needed feature, thank you! 🎉

@UziTechUziTech left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Awesome 💯 🎉

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: docsDocumentation changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@aprotim@UziTech@styfle