I want to turn wikitext into HTML for display on a web front-end I'm building. For what I'm doing, all I need is a few constructs like wiklinks, bold, and italic, which I'm able to do with a smallish amount of mwparserfromhell code.
The one annoyance I've got now is I'm using bootstrap https://getbootstrap.com/ in a web front-end, so I don't want <b> and <i> HTML tags. I want is <span class="fw-bold"> https://getbootstrap.com/docs/5.0/utilities/text/#font-weight-and-italics (and likewise class="fst-italic") Is there some way to tell mwparserfromhell.nodes.Tag to use that alternate markup when it processes bold or italic wikicode?
Hi,
On 2/6/23 15:27, Roy Smith wrote:
I want to turn wikitext into HTML for display on a web front-end I'm building. For what I'm doing, all I need is a few constructs like wiklinks, bold, and italic, which I'm able to do with a smallish amount of mwparserfromhell code.
The one annoyance I've got now is I'm using bootstrap https://getbootstrap.com/ in a web front-end, so I don't want <b> and <i> HTML tags. I want is <span class="fw-bold"> https://getbootstrap.com/docs/5.0/utilities/text/#font-weight-and-italics (and likewise class="fst-italic") Is there some way to tell mwparserfromhell.nodes.Tag to use that alternate markup when it processes bold or italic wikicode?
I don't know the answer to your question of modifying mwparserfromhell to output different tags, but...
Since you say your wikitext is pretty simple, just links, bold and italic, you could probably get away with just regexing those tags into your preferred span tags.
A better and more robust solution would be to use something like beautifulsoup4 to modify your HTML[1]. I would personally have taken the wikitext, run it through api.php?action=parse or the wt2html Parsoid API, and then used an HTML parser to modify it as needed.
[1] https://beautiful-soup-4.readthedocs.io/en/latest/#modifying-the-tree
-- Kunal / Legoktm
That only works on the content of an entire page, doesn't it? I've just got a short snippet of wikitext that I've already parsed out of a page. Specifically, a proposed DYK hook, such as:
that '''[[Edward A. Hanna]]''' wanted to eliminate the [[New York State Assembly]] while he served in it, and later wanted to close down the government of the city of [[Utica, New York|Utica]] while he was its mayor?
On Feb 6, 2023, at 4:10 PM, Kunal Mehta legoktm@debian.org wrote:
A better and more robust solution would be to use something like beautifulsoup4 to modify your HTML[1]. I would personally have taken the wikitext, run it through api.php?action=parse or the wt2html Parsoid API, and then used an HTML parser to modify it as needed.
Hi,
On 2/6/23 18:59, Roy Smith wrote:
That only works on the content of an entire page, doesn't it? I've just got a short snippet of wikitext that I've already parsed out of a page.
Nope, it works for any piece of wikitext you want.
Specifically, a proposed DYK hook, such as:
that '''[[Edward A. Hanna]]''' wanted to eliminate the [[New York State Assembly]] while he served in it, and later wanted to close down the government of the city of [[Utica, New York|Utica]] while he was its mayor?
Try https://w.wiki/6Js7 (ApiSandbox with that text + some parse options preloaded).
-- Kunal / Legoktm
Cool, thanks.
On Feb 6, 2023, at 8:05 PM, Kunal Mehta legoktm@debian.org wrote:
Hi,
On 2/6/23 18:59, Roy Smith wrote:
That only works on the content of an entire page, doesn't it? I've just got a short snippet of wikitext that I've already parsed out of a page.
Nope, it works for any piece of wikitext you want.
Specifically, a proposed DYK hook, such as:
that '''[[Edward A. Hanna]]''' wanted to eliminate the [[New York State Assembly]] while he served in it, and later wanted to close down the government of the city of [[Utica, New York|Utica]] while he was its mayor?
Try https://w.wiki/6Js7 (ApiSandbox with that text + some parse options preloaded).
-- Kunal / Legoktm _______________________________________________ pywikibot mailing list -- pywikibot@lists.wikimedia.org Public archives at https://lists.wikimedia.org/hyperkitty/list/pywikibot@lists.wikimedia.org/me... To unsubscribe send an email to pywikibot-leave@lists.wikimedia.org