Markdown to HTML Multi-Point Injector
Convert Markdown to HTML and inject it at multiple CSS-selector-targeted points within your base HTML document. Real-time preview, export, and copy.
About
Injecting converted Markdown into an existing HTML document at precise locations requires parsing two separate syntaxes and resolving CSS selectors against a live DOM tree. Getting the insertion position wrong means content renders outside its semantic container, breaking layout cascades and accessibility landmarks. This tool parses your Markdown through a multi-pass regex engine covering headings, lists, tables, code blocks, and inline formatting, then uses DOMParser to build a virtual document from your base HTML. Each injection point targets elements via standard CSS selectors (selector) and a positional keyword (beforebegin, afterbegin, beforeend, afterend), matching the insertAdjacentHTML specification. Multiple injection points execute sequentially, allowing batch content placement in a single operation. The tool approximates browser-native selector resolution. Selectors that depend on runtime state (e.g., :hover) or JavaScript-injected classes will not match in the virtual DOM context.
Formulas
The injection engine operates in a deterministic pipeline of 4 stages:
Where M is the raw Markdown input and Hmd is the resulting HTML fragment. The parser applies regex transformations in priority order: fenced code blocks first (to protect content from further parsing), then block-level structures (headings, lists, blockquotes, tables, horizontal rules), and finally inline formatting (bold, italic, code, links, images).
The base HTML string Hbase is parsed into a virtual document D.
Each injection point Pi contains three parameters: selector (a CSS selector string), pos (one of beforebegin, afterbegin, beforeend, afterend), and idx (zero-based occurrence index, defaulting to 0 for the first match). The final serialized output is Hout = serialize(D).
Reference Data
| Markdown Syntax | HTML Output | Notes |
|---|---|---|
# Heading | <h1> | Levels 1 - 6 supported |
**bold** | <strong> | Double asterisks or underscores |
*italic* | <em> | Single asterisks or underscores |
~~strike~~ | <del> | Double tildes |
`code` | <code> | Inline code span |
```lang | <pre><code> | Fenced code block with optional language class |
> quote | <blockquote> | Nested with multiple > |
- item | <ul><li> | Also * or + prefixes |
1. item | <ol><li> | Ordered list numbering |
- [x] task | <input type="checkbox"> | Checked or unchecked |
[text](url) | <a href> | Inline link |
 | <img> | Image with alt text |
--- | <hr> | Three or more dashes, asterisks, or underscores |
| A | B | | <table> | Pipe-delimited table with alignment |
Position: beforebegin | Before the element itself | Outside, preceding sibling |
Position: afterbegin | First child of the element | Inside, prepended |
Position: beforeend | Last child of the element | Inside, appended |
Position: afterend | After the element itself | Outside, following sibling |
Selector: .class | Class selector | Matches all by default; use occurrence index to narrow |
Selector: #id | ID selector | Should match exactly 1 element |
Selector: tag | Element selector | Matches all instances of that tag |
Selector: [attr] | Attribute selector | Standard CSS attribute selectors supported |
Selector: div > p | Child combinator | Direct child only |
Selector: div p | Descendant combinator | Any depth descendant |
Selector: :first-child | Pseudo-class | Structural pseudo-classes work in virtual DOM |
Selector: :nth-child(n) | Pseudo-class | Functional pseudo-classes supported |
Frequently Asked Questions
<div>, <span>, or other tags in your Markdown and they will appear in the converted output. However, unclosed tags or malformed HTML may produce unexpected results when inserted into the base document's DOM tree.