Parsedown: sub/superscript












1















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.










share|improve this question





























    1















    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.










    share|improve this question



























      1












      1








      1








      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.










      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 2 at 5:10







      Mark Messa

















      asked Aug 20 '18 at 21:51









      Mark MessaMark Messa

      19913




      19913
























          1 Answer
          1






          active

          oldest

          votes


















          0
















          1. Append Superscript and Tilde 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'),
            );



          2. Define methods inlineSuperscript. It should look pretty much like inlineStrikethrough:



            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',
            )
            ),
            );
            }
            }



          3. Define methods inlineTilde and delete method inlineStrikethrough. It should look pretty much like inlineEmphasis:



            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',
            )
            ),
            );
            }



          4. Add the new symbol to $inlineMarkerList:



            protected $inlineMarkerList = '!*_&[:<`~\^';







          share|improve this answer

























            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
            });


            }
            });














            draft saved

            draft discarded


















            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









            0
















            1. Append Superscript and Tilde 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'),
              );



            2. Define methods inlineSuperscript. It should look pretty much like inlineStrikethrough:



              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',
              )
              ),
              );
              }
              }



            3. Define methods inlineTilde and delete method inlineStrikethrough. It should look pretty much like inlineEmphasis:



              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',
              )
              ),
              );
              }



            4. Add the new symbol to $inlineMarkerList:



              protected $inlineMarkerList = '!*_&[:<`~\^';







            share|improve this answer






























              0
















              1. Append Superscript and Tilde 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'),
                );



              2. Define methods inlineSuperscript. It should look pretty much like inlineStrikethrough:



                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',
                )
                ),
                );
                }
                }



              3. Define methods inlineTilde and delete method inlineStrikethrough. It should look pretty much like inlineEmphasis:



                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',
                )
                ),
                );
                }



              4. Add the new symbol to $inlineMarkerList:



                protected $inlineMarkerList = '!*_&[:<`~\^';







              share|improve this answer




























                0












                0








                0









                1. Append Superscript and Tilde 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'),
                  );



                2. Define methods inlineSuperscript. It should look pretty much like inlineStrikethrough:



                  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',
                  )
                  ),
                  );
                  }
                  }



                3. Define methods inlineTilde and delete method inlineStrikethrough. It should look pretty much like inlineEmphasis:



                  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',
                  )
                  ),
                  );
                  }



                4. Add the new symbol to $inlineMarkerList:



                  protected $inlineMarkerList = '!*_&[:<`~\^';







                share|improve this answer

















                1. Append Superscript and Tilde 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'),
                  );



                2. Define methods inlineSuperscript. It should look pretty much like inlineStrikethrough:



                  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',
                  )
                  ),
                  );
                  }
                  }



                3. Define methods inlineTilde and delete method inlineStrikethrough. It should look pretty much like inlineEmphasis:



                  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',
                  )
                  ),
                  );
                  }



                4. Add the new symbol to $inlineMarkerList:



                  protected $inlineMarkerList = '!*_&[:<`~\^';








                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Aug 21 '18 at 23:24

























                answered Aug 21 '18 at 22:48









                Mark MessaMark Messa

                19913




                19913
































                    draft saved

                    draft discarded




















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    MongoDB - Not Authorized To Execute Command

                    in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

                    How to fix TextFormField cause rebuild widget in Flutter