Showdown: Options for indenting text

Created on 8 Dec 2017  路  7Comments  路  Source: showdownjs/showdown

Options for indenting text to center, left and right.

help wanted

Most helpful comment

That effect can be accomplished trough CSS.

All 7 comments

That effect can be accomplished trough CSS.

can u help ?
how can i accomplish this .

Using the pseudo selector :nth-child(2), for instance. Check this working fiddle

Example:

markdown:

this is paragraph right aligned

this paragraph is centered

this paragraph is left aligned

css:

p:nth-child(1) { text-align: right; }
p:nth-child(2) { text-align: center; }

Donate Click here to lend your support to: ShowdownJS website and testing platform and make a donation at pledgie.com

As you know, ShowdownJS is a free library and it will remain free forever. However, maintaining and improving the library costs time and money.
If you like our work and find our library useful, please donate through Pledgie or directly through paypal!! Your contribution will be greatly appreciated and help us continue to develop this awesome library.

tivie thankyou for the quick reply but i guess this won't resolve my issue.
let me briefly explain my problem what we are doing is that we are using showdownjs to convert markup to html and save markup to database and then generate pdf from the same markup.

now what is the the requirement is that we need new set of cheat sheet code to align the text to left right and center. i.e BOLD somethings like ---align left---
now do i have to write a plugin for the same ?

Well, if I understand you correctly, you need new "markup" to align text. That can be accomplished through an extension.

Now, align only works in block elements (you can't have partial alignments in the same line), but you can create an extension that does what you want.

Check this fiddle for an example.

Extension

showdown.extension('palign', function() {
  return [{
    type: 'listener',
    listeners: {
      'blockGamut.before': function (event, text, converter, options, globals) {
        text = text.replace(/^--:([\s\S]+?)--:$/gm, function (wm, txt) {
          return '<div style="text-align: right;">' + converter.makeHtml(txt) + '</div>';
        });
        text = text.replace(/^-:-([\s\S]+?)-:-$/gm, function (wm, txt) {
          return '<div style="text-align: center;">' + converter.makeHtml(txt) + '</div>';
        });
       text = text.replace(/^:--([\s\S]+?):--$/gm, function (wm, txt) {
          return '<div style="text-align: left;">' + converter.makeHtml(txt) + '</div>';
        });
        return text;
      }
    }
  }];
});

Syntax

--:right align--:

-:-center align-:-

:--left align:--

tivie thankyou for your help 馃憤
I have incorporated this solution in my project.

@savsharma2 Glad I could help.

Donate Click here to lend your support to: ShowdownJS website and testing platform and make a donation at pledgie.com

As you know, ShowdownJS is a free library and it will remain free forever. However, maintaining and improving the library costs time and money.
If you like our work and find our library useful, please donate through Pledgie or directly through paypal!! Your contribution will be greatly appreciated and help us continue to develop this awesome library.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jeud picture jeud  路  3Comments

KirkMunro picture KirkMunro  路  6Comments

xduseko picture xduseko  路  3Comments

BusyHe picture BusyHe  路  4Comments

reisraff picture reisraff  路  5Comments