-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Support for sub- & superscript, without using html tags #2709
Comments
Also
So which one would override the other for GitHub? |
The subscript method should not allow spaces in the text and I guess it’s only valid when written against a character or word. Something like |
You could create an extension for these something like: // superscript.js
export default {
name: 'superscript',
level: 'inline',
start(src) { return src.indexOf('^'); },
tokenizer(src) {
const match = src.match(/^\^(\w+)\^/);
if (!match) {
return;
}
return {
type: 'superscript',
raw: match[0],
text: match[1]
};
},
renderer(token) {
return `<sup>${token.text}</sup>`;
}
}; // subscript.js
export default {
name: 'subscript',
level: 'inline',
start(src) { return src.indexOf('~'); },
tokenizer(src) {
const match = src.match(/^~(\w+)~/);
if (!match) {
return;
}
return {
type: 'subscript',
raw: match[0],
text: match[1]
};
},
renderer(token) {
return `<sub>${token.text}</sub>`;
}
}; import superscript from './superscript.js';
import subscript from './subscript.js';
import { marked } from 'marked';
marked.use({
extensions: [
superscript,
subscript
]
};
console.log(marked.parse('test^superscript^ test~subscript~'));
// <p>test<sup>superscript</sup> test<sub>subscript</sub></p> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the feature
Currently marked.js doesn't seem to have support for sub- & superscript, without using html tags. This would be possible by using
E=MC^2^
andlog 2~a~
as examplesWhy is this feature necessary?
It would compliment the overal usability of marked.js, which would make reading and writing the markdown much cleaner instead of using html in the text.
Describe alternatives you've considered
As described on subscript-in-markdown, and I'm not sure if this is documented anywhere else, using
E=MC^2^
would result in superscript, whilelog 2~a~
would result in subscript. Unfortunately, GitHub also doesn't support it.The text was updated successfully, but these errors were encountered: