Parsedown: sub/superscript
The current version of Parsedown 1.8.0-beta-5 doesn't have a builtin syntax for sub/superscript. Although CommonMark doesn't specify such syntax, several other lightweight markup languages (ex: Parsedown Extreme, Textile) use a syntax similar to the following:
in: 19^th^
out: 19<sup>th</sup>
in: H~2~O
out: H<sub>2</sub>O
Question
What steps should be taken in order to modify Parsedown.php
file and include such syntax?
Note: This issue has already come up other times (Parsedown, add sub/superscript). However, there is still no step-by-step guide explaining what modifications should be done in Parsedown.php
file in order to achieve that.
php commonmark parsedown
add a comment |
The current version of Parsedown 1.8.0-beta-5 doesn't have a builtin syntax for sub/superscript. Although CommonMark doesn't specify such syntax, several other lightweight markup languages (ex: Parsedown Extreme, Textile) use a syntax similar to the following:
in: 19^th^
out: 19<sup>th</sup>
in: H~2~O
out: H<sub>2</sub>O
Question
What steps should be taken in order to modify Parsedown.php
file and include such syntax?
Note: This issue has already come up other times (Parsedown, add sub/superscript). However, there is still no step-by-step guide explaining what modifications should be done in Parsedown.php
file in order to achieve that.
php commonmark parsedown
add a comment |
The current version of Parsedown 1.8.0-beta-5 doesn't have a builtin syntax for sub/superscript. Although CommonMark doesn't specify such syntax, several other lightweight markup languages (ex: Parsedown Extreme, Textile) use a syntax similar to the following:
in: 19^th^
out: 19<sup>th</sup>
in: H~2~O
out: H<sub>2</sub>O
Question
What steps should be taken in order to modify Parsedown.php
file and include such syntax?
Note: This issue has already come up other times (Parsedown, add sub/superscript). However, there is still no step-by-step guide explaining what modifications should be done in Parsedown.php
file in order to achieve that.
php commonmark parsedown
The current version of Parsedown 1.8.0-beta-5 doesn't have a builtin syntax for sub/superscript. Although CommonMark doesn't specify such syntax, several other lightweight markup languages (ex: Parsedown Extreme, Textile) use a syntax similar to the following:
in: 19^th^
out: 19<sup>th</sup>
in: H~2~O
out: H<sub>2</sub>O
Question
What steps should be taken in order to modify Parsedown.php
file and include such syntax?
Note: This issue has already come up other times (Parsedown, add sub/superscript). However, there is still no step-by-step guide explaining what modifications should be done in Parsedown.php
file in order to achieve that.
php commonmark parsedown
php commonmark parsedown
edited Jan 2 at 5:10
Mark Messa
asked Aug 20 '18 at 21:51


Mark MessaMark Messa
19913
19913
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Append
Superscript
andTilde
in$InlineTypes
:
protected $InlineTypes = array(
'!' => array('Image'),
'&' => array('SpecialCharacter'),
'*' => array('Emphasis'),
':' => array('Url'),
'<' => array('UrlTag', 'EmailTag', 'Markup'),
'[' => array('Link'),
'_' => array('Emphasis'),
'`' => array('Code'),
'~' => array('Tilde'),
'^' => array('Superscript'),
'\' => array('EscapeSequence'),
);
Define methods
inlineSuperscript
. It should look pretty much likeinlineStrikethrough
:
protected function inlineSuperscript($Excerpt)
{
if (preg_match('/^^(.+?)^/', $Excerpt['text'], $matches))
{
return array(
'extent' => strlen($matches[0]),
'element' => array(
'name' => 'sup',
'handler' => array(
'function' => 'lineElements',
'argument' => $matches[1],
'destination' => 'elements',
)
),
);
}
}
Define methods
inlineTilde
and delete methodinlineStrikethrough
. It should look pretty much likeinlineEmphasis
:
protected function inlineTilde($Excerpt)
{
if ( ! isset($Excerpt['text'][1]))
{
return;
}
$marker = $Excerpt['text'][0];
if ($Excerpt['text'][1] === $marker and preg_match('/^~~(?=S)(.+?)(?<=S)~~/', $Excerpt['text'], $matches))
{
$emphasis = 'del';
}
elseif (preg_match('/^~(?=S)(.+?)(?<=S)~/', $Excerpt['text'], $matches))
{
$emphasis = 'sub';
}
else
{
return;
}
return array(
'extent' => strlen($matches[0]),
'element' => array(
'name' => $emphasis,
'handler' => array(
'function' => 'lineElements',
'argument' => $matches[1],
'destination' => 'elements',
)
),
);
}
Add the new symbol to
$inlineMarkerList
:
protected $inlineMarkerList = '!*_&[:<`~\^';
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51938965%2fparsedown-sub-superscript%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Append
Superscript
andTilde
in$InlineTypes
:
protected $InlineTypes = array(
'!' => array('Image'),
'&' => array('SpecialCharacter'),
'*' => array('Emphasis'),
':' => array('Url'),
'<' => array('UrlTag', 'EmailTag', 'Markup'),
'[' => array('Link'),
'_' => array('Emphasis'),
'`' => array('Code'),
'~' => array('Tilde'),
'^' => array('Superscript'),
'\' => array('EscapeSequence'),
);
Define methods
inlineSuperscript
. It should look pretty much likeinlineStrikethrough
:
protected function inlineSuperscript($Excerpt)
{
if (preg_match('/^^(.+?)^/', $Excerpt['text'], $matches))
{
return array(
'extent' => strlen($matches[0]),
'element' => array(
'name' => 'sup',
'handler' => array(
'function' => 'lineElements',
'argument' => $matches[1],
'destination' => 'elements',
)
),
);
}
}
Define methods
inlineTilde
and delete methodinlineStrikethrough
. It should look pretty much likeinlineEmphasis
:
protected function inlineTilde($Excerpt)
{
if ( ! isset($Excerpt['text'][1]))
{
return;
}
$marker = $Excerpt['text'][0];
if ($Excerpt['text'][1] === $marker and preg_match('/^~~(?=S)(.+?)(?<=S)~~/', $Excerpt['text'], $matches))
{
$emphasis = 'del';
}
elseif (preg_match('/^~(?=S)(.+?)(?<=S)~/', $Excerpt['text'], $matches))
{
$emphasis = 'sub';
}
else
{
return;
}
return array(
'extent' => strlen($matches[0]),
'element' => array(
'name' => $emphasis,
'handler' => array(
'function' => 'lineElements',
'argument' => $matches[1],
'destination' => 'elements',
)
),
);
}
Add the new symbol to
$inlineMarkerList
:
protected $inlineMarkerList = '!*_&[:<`~\^';
add a comment |
Append
Superscript
andTilde
in$InlineTypes
:
protected $InlineTypes = array(
'!' => array('Image'),
'&' => array('SpecialCharacter'),
'*' => array('Emphasis'),
':' => array('Url'),
'<' => array('UrlTag', 'EmailTag', 'Markup'),
'[' => array('Link'),
'_' => array('Emphasis'),
'`' => array('Code'),
'~' => array('Tilde'),
'^' => array('Superscript'),
'\' => array('EscapeSequence'),
);
Define methods
inlineSuperscript
. It should look pretty much likeinlineStrikethrough
:
protected function inlineSuperscript($Excerpt)
{
if (preg_match('/^^(.+?)^/', $Excerpt['text'], $matches))
{
return array(
'extent' => strlen($matches[0]),
'element' => array(
'name' => 'sup',
'handler' => array(
'function' => 'lineElements',
'argument' => $matches[1],
'destination' => 'elements',
)
),
);
}
}
Define methods
inlineTilde
and delete methodinlineStrikethrough
. It should look pretty much likeinlineEmphasis
:
protected function inlineTilde($Excerpt)
{
if ( ! isset($Excerpt['text'][1]))
{
return;
}
$marker = $Excerpt['text'][0];
if ($Excerpt['text'][1] === $marker and preg_match('/^~~(?=S)(.+?)(?<=S)~~/', $Excerpt['text'], $matches))
{
$emphasis = 'del';
}
elseif (preg_match('/^~(?=S)(.+?)(?<=S)~/', $Excerpt['text'], $matches))
{
$emphasis = 'sub';
}
else
{
return;
}
return array(
'extent' => strlen($matches[0]),
'element' => array(
'name' => $emphasis,
'handler' => array(
'function' => 'lineElements',
'argument' => $matches[1],
'destination' => 'elements',
)
),
);
}
Add the new symbol to
$inlineMarkerList
:
protected $inlineMarkerList = '!*_&[:<`~\^';
add a comment |
Append
Superscript
andTilde
in$InlineTypes
:
protected $InlineTypes = array(
'!' => array('Image'),
'&' => array('SpecialCharacter'),
'*' => array('Emphasis'),
':' => array('Url'),
'<' => array('UrlTag', 'EmailTag', 'Markup'),
'[' => array('Link'),
'_' => array('Emphasis'),
'`' => array('Code'),
'~' => array('Tilde'),
'^' => array('Superscript'),
'\' => array('EscapeSequence'),
);
Define methods
inlineSuperscript
. It should look pretty much likeinlineStrikethrough
:
protected function inlineSuperscript($Excerpt)
{
if (preg_match('/^^(.+?)^/', $Excerpt['text'], $matches))
{
return array(
'extent' => strlen($matches[0]),
'element' => array(
'name' => 'sup',
'handler' => array(
'function' => 'lineElements',
'argument' => $matches[1],
'destination' => 'elements',
)
),
);
}
}
Define methods
inlineTilde
and delete methodinlineStrikethrough
. It should look pretty much likeinlineEmphasis
:
protected function inlineTilde($Excerpt)
{
if ( ! isset($Excerpt['text'][1]))
{
return;
}
$marker = $Excerpt['text'][0];
if ($Excerpt['text'][1] === $marker and preg_match('/^~~(?=S)(.+?)(?<=S)~~/', $Excerpt['text'], $matches))
{
$emphasis = 'del';
}
elseif (preg_match('/^~(?=S)(.+?)(?<=S)~/', $Excerpt['text'], $matches))
{
$emphasis = 'sub';
}
else
{
return;
}
return array(
'extent' => strlen($matches[0]),
'element' => array(
'name' => $emphasis,
'handler' => array(
'function' => 'lineElements',
'argument' => $matches[1],
'destination' => 'elements',
)
),
);
}
Add the new symbol to
$inlineMarkerList
:
protected $inlineMarkerList = '!*_&[:<`~\^';
Append
Superscript
andTilde
in$InlineTypes
:
protected $InlineTypes = array(
'!' => array('Image'),
'&' => array('SpecialCharacter'),
'*' => array('Emphasis'),
':' => array('Url'),
'<' => array('UrlTag', 'EmailTag', 'Markup'),
'[' => array('Link'),
'_' => array('Emphasis'),
'`' => array('Code'),
'~' => array('Tilde'),
'^' => array('Superscript'),
'\' => array('EscapeSequence'),
);
Define methods
inlineSuperscript
. It should look pretty much likeinlineStrikethrough
:
protected function inlineSuperscript($Excerpt)
{
if (preg_match('/^^(.+?)^/', $Excerpt['text'], $matches))
{
return array(
'extent' => strlen($matches[0]),
'element' => array(
'name' => 'sup',
'handler' => array(
'function' => 'lineElements',
'argument' => $matches[1],
'destination' => 'elements',
)
),
);
}
}
Define methods
inlineTilde
and delete methodinlineStrikethrough
. It should look pretty much likeinlineEmphasis
:
protected function inlineTilde($Excerpt)
{
if ( ! isset($Excerpt['text'][1]))
{
return;
}
$marker = $Excerpt['text'][0];
if ($Excerpt['text'][1] === $marker and preg_match('/^~~(?=S)(.+?)(?<=S)~~/', $Excerpt['text'], $matches))
{
$emphasis = 'del';
}
elseif (preg_match('/^~(?=S)(.+?)(?<=S)~/', $Excerpt['text'], $matches))
{
$emphasis = 'sub';
}
else
{
return;
}
return array(
'extent' => strlen($matches[0]),
'element' => array(
'name' => $emphasis,
'handler' => array(
'function' => 'lineElements',
'argument' => $matches[1],
'destination' => 'elements',
)
),
);
}
Add the new symbol to
$inlineMarkerList
:
protected $inlineMarkerList = '!*_&[:<`~\^';
edited Aug 21 '18 at 23:24
answered Aug 21 '18 at 22:48


Mark MessaMark Messa
19913
19913
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51938965%2fparsedown-sub-superscript%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown