# MDParser

This page covers `MDParser`, the Markdown-to-HTML class that needs no editor or viewer UI.

## Construction

```javascript
const parser = new MDParser({ standard: false, text: "# Default" });
```

| Option | Type | Default | Description |
|---|---|---|---|
| `standard` | `boolean` | `true` | When `true`, only standard syntax is handled; see [Standard Mode](/standard-mode) |
| `text` | `string` | `""` | Default text used when `parse()` gets no argument |

## parse()

```javascript
parser.parse(text?) // => string
```

| Input | Behavior |
|---|---|
| `text` is a string | Converts that string |
| `text` is `undefined` or `null` | Converts the constructor's `text` |
| Empty string | Returns `"<br>"` (the default text is not used) |

The return value is an HTML string that may carry leading or trailing newlines. Every call runs the full pipeline; nothing is cached.

## Differences from the Viewer

| Item | `MDParser` | `MDViewer` |
|---|---|---|
| Default mode | Standard | Extended (fixed) |
| Hashtags | Not converted | Per `hashtag.path` |
| Code highlighting, Mermaid | Only emits the `prettyprint` class and `.mermaid` containers; call `PR.prettyPrint()` / `mermaid.run()` yourself | Run automatically after render |
| Copy button | Emits `<button class="copy">` with no handler | Bound to the clipboard automatically |

## Environment Requirements

`MDParser` creates no DOM container, but still needs a browser environment:

- Conversion builds HTML fragments with `document.createElement`
- Loading the bundle reads `window.matchMedia` and inserts CDN resources into `<head>`; see [Runtime Dependencies](/runtime-dependencies)
- A link to Vimeo triggers a synchronous XHR for the thumbnail (extended mode), blocking the main thread during conversion

To use it in Node.js, pair it with a DOM implementation such as jsdom and provide `window.matchMedia` first.

## Example

```javascript
const parser = new MDParser({ standard: false });
const html = parser.parse("```js\nconst a = 1;\n```");
document.querySelector("#out").innerHTML = html;
PR.prettyPrint();
```

Read [Security](/security) before writing the output into `innerHTML`.
