Markdown-to-Wikitext converter

MD2Wiki

A pure front-end, single-file tool that converts Markdown to MediaWiki wikitext (Wikitext) in real time. No installation or internet connection required—just open it in a browser to use.


Features

Inline Formatting

  • Bold, italic, bold italic
  • Strikethrough → <s>
  • ==Highlight== → <mark>
  • Superscript ^x^ → <sup>, subscript ~x~ → <sub>
  • `Inline code` → <code>
  • Links [text](url) → [url text]
  • Images ![alt](url) → [[File:url|alt]] (external images fall back to regular external links)
  • Autolinks <https://...> → output URL directly
  • Footnote references [^id] → <ref name="id">…</ref>
  • Emoji shortcodes :smile: → :grinning_face_with_smiling_eyes:
  • Inline math $...$ → <math>...</math>

Block Formatting

  • ATX headings # ~ ###### → = Heading =
  • Setext headings (underlines === / ---) → = Heading =
  • Heading anchors {#custom-id} → <span id="custom-id"></span>
  • Horizontal rules --- / *** / ___ → ----
  • Tables (left/center/right alignment supported) → {| class="wikitable" … |}
  • Fenced code blocks ```lang → <syntaxhighlight lang="lang"> (can be switched to <pre>)
  • Block quotes > → <blockquote>
  • Ordered / unordered lists, with nesting support → # / *
  • Task lists - [x] / - [ ] → ☑ / ☐
  • Definition lists Term + : Definition → ; Term / : Definition
  • Math blocks $$...$$ → <math display="block">
  • Comments [//]: # (content) → <!-- content -->
  • Table of contents [TOC] → __TOC__

Automatic Footnote Processing

  • Extracts all [^id]: content definition lines and removes them from the body
  • Converts [^id] in the body to <ref>
  • Automatically appends <references/> at the end if the page uses footnotes

Syntax Workarounds (HTML Tag Adaptation)

  • <img src="..." width="..." alt="..."> → [[File:...|100px|alt]] (local images)
  • <a href="..." target="_blank">text</a> → [url text]
  • <font color="red"> → <span style="color:red">
  • <p style="..." align="..."> → <div style="...">
  • <ins> / <u> / <del> / <mark> / <kbd> are preserved as-is (natively supported by the wiki)

Interface

  • Two-column layout: Markdown input on the left, real-time wikitext output on the right
  • Top toolbar for toggling conversion features
  • Real-time line and character counts
  • One-click output copying and .wiki file downloads
  • The Tab key inserts two spaces for convenient indentation
  • Dark theme with responsive layout

Toolbar Options

Option Default Description
Emoji shortcodes Enabled Replaces :smile: and others with Unicode Emoji
Footnotes → <ref> Enabled Extracts footnote definitions and converts them to <ref> tags
Code block highlighting Enabled Outputs code blocks as <syntaxhighlight>; outputs <pre> when disabled
Task lists :check_box_with_check:/☐ Enabled Converts - [x] / - [ ] to ☑ / ☐
Math formulas → <math> Enabled Converts $...$ and $$...$$ to <math>
Table class wikitable CSS class for table output

Conversion Reference (Partial)

Markdown Wikitext
# Heading = Heading =
**Bold** '''Bold'''
*Italic* ''Italic''
~~Strikethrough~~ <s>Strikethrough</s>
==Highlight== <mark>Highlight</mark>
[text](url) [url text]
![alt](img.png) [[File:img.png|alt]]
`code` <code>code</code>
- [x] Task * ☑ Task
> Quote <blockquote>Quote</blockquote>
[^1] + [^1]: Note <ref name="1">Note</ref> + <references/> at the end
:smile: :grinning_face_with_smiling_eyes:
$x^2$ <math>x^2</math>

Implementation Notes

  • Pure JavaScript, single file, no external dependencies
  • Inline parsing uses a protection mechanism: inline code is extracted first to prevent *, _, and other characters inside it from being misparsed
  • Block parsing scans line by line and supports nested quotes and lists
  • Footnote definitions are extracted during preprocessing; <ref> tags are generated in order of first appearance in the body, and repeated references use <ref name="..."/>
  • Output uses <textarea readonly>; copying primarily uses navigator.clipboard, falling back to execCommand('copy') in insecure contexts

Known Limitations

  • Emoji shortcodes include only a common subset and do not cover the complete GitHub Emoji list; expand as needed
  • Continued footnote lines support only simple continuation lines indented by 4 spaces or a Tab; complex multi-paragraph footnotes may require manual adjustment
  • Math formulas are wrapped directly in <math> as-is; LaTeX syntax is not validated or converted
  • Task lists use Unicode ☑ / ☐ rather than wiki templates; modify them yourself if templates are needed
  • HTML workarounds support only common tags; wiki support for attributes such as style and target is limited, and they may be filtered
  • External images are not converted to [[File:...]] because the wiki does not support external images; they are retained as regular links
  • Tables do not support line breaks within cells, block-level elements within cells, or other complex cases
  • Browser compatibility: uses regular expression lookbehind ((?<!...)), requiring a modern browser (Chrome 62+, Firefox 78+, Safari 16.4+)

Custom Extensions

Expanding Emoji Shortcodes

Add key-value pairs to the EMOJI object at the beginning of the script:

const EMOJI = {
  smile: '😄',
  // Add new entry:
  my_custom_emoji: '🎯'
};

Modifying the Default Table Class

Change it in the toolbar input field, or directly edit value="wikitable" in the HTML.

Adding New Conversion Rules

  • Inline rules: add text = text.replace(...) statements in order in the inline() function
  • Block rules: add branches to the while loop in convertBlocks()

License

MPL2.0

github link: [upvote]Click me[/upvote]
Deployed GitHub Pages link [upvote]Click me[/upvote]

2 Likes

Try it right away