Options for indenting text to center, left and right.
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
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.
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;
}
}
}];
});
--: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
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.
Most helpful comment
That effect can be accomplished trough CSS.