-
Notifications
You must be signed in to change notification settings - Fork 6
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
Generating markdown headers instead of HTML #17
Conversation
Idiomatic Markdown is worth pursuing, but I believe this change would break an important feature of Transcribe: clean fragment identifiers. The following links point to the same section, but one is much nicer than the other:
The former is generated by Transcribe; the latter by GitHub. Could we better interoperate with markdown-toc without sacrificing clean fragment identifiers? |
Two possible approaches:
What do you think would be best, if either? |
The first option doesn't suit me because I sometimes rely on case sensitivity. The follow links point to different sections:
The second option sounds promising. The element should be a Do Markdown parsers respect Markdown syntax inside HTML elements? |
@davidchambers I was thinking ## <span name="foo">Foo</span> Which would render to: <h2><span name="foo">Foo</span></h2> |
ff2f982
to
7c36801
Compare
@davidchambers Okay, I've made an update. Now the PR does the following:
I tried the |
Thanks, @DavidMikeSimon. I'm eager to put your updated version through its paces. :) |
bin/transcribe
Outdated
'</a>' + | ||
'</code>' + | ||
'</' + esc(tagName) + '>\n' | ||
markdownHeadingPrefix + ' ' + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since markdownHeadingPrefix
is referenced just once, let's replace it with its definition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could use '######'.slice(0, options.headingLevel)
in place of the Ramda version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I spent some time formatting this code. Let's use this:
//. formatSignature :: Options -> String -> Number -> String -> String
var formatSignature = R.curry(function(options, filename, line, signature) {
return '######'.slice(0, options.headingLevel) + ' ' +
'<a name="' + esc(signature.split(' :: ')[0]) + '"' +
' href="' + esc(options.url.replace('{filename}', filename)
.replace('{line}', line)) + '">' +
'`' + esc(controlWrapping(signature)) + '`' +
'</a>\n';
});
I created sanctuary-js/sanctuary-type-classes@v8.1.1...davidchambers/transcribe to test these changes. I don't see any differences in the rendered output, so this is a strict upgrade. Not only is the text more accessible to markdown-toc, it's more elegant. :) |
@davidchambers Ok, formatted as suggested |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
This makes the output more idiomatically Markdown-y, and in particular works better with Markdown-parsing tools like markdown-toc