# wikiparse

> Wikipedia/MediaWiki syntax parser

Latest version **1.0.27** (published 2022-01-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install wikiparse
pnpm add wikiparse
yarn add wikiparse
bun add wikiparse
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.27 |
| Published | 2022-01-16 |
| First published | 2022-01-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 44 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Yury Shulaev |
| Maintainers | yuryshulaev |
| Keywords | wiki, wikipedia, mediawiki, syntax, parser |

## Links

- npm: https://www.npmjs.com/package/wikiparse
- Repository: https://github.com/yuryshulaev/wikiparse
- Issues: https://github.com/yuryshulaev/wikiparse/issues
- npm.io page: https://npm.io/package/wikiparse

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 1.0.27 (latest) — 2022-01-16
- 1.0.26 — 2022-01-16
- 1.0.25 — 2022-01-16
- 1.0.24 — 2022-01-15
- 1.0.23 — 2022-01-15
- 1.0.22 — 2022-01-15
- 1.0.21 — 2022-01-09
- 1.0.20 — 2022-01-09
- 1.0.19 — 2022-01-09
- 1.0.18 — 2022-01-09
- 1.0.17 — 2022-01-09
- 1.0.16 — 2022-01-08
- 1.0.15 — 2022-01-08
- 1.0.14 — 2022-01-08
- 1.0.13 — 2022-01-06

## README

# wikiparse — Wikipedia/MediaWiki syntax parser

Converts wiki markup into a JSON abstract syntax tree or plain text.

## Installation

```
npm i wikiparse
```

## Basic usage

```javascript
import {parse} from 'wikiparse';

const ast = parse(`'''Cats''', also called '''domestic cats''' (''Felis catus''), are small, [[carnivore|carnivorous]] [[mammal]]s`);
console.log(ast);
```

```json
[
  {"type": "bold", "content": ["Cats"]},
  ", also called ",
  {"type": "bold", "content": ["domestic cats"]},
  " (",
  {"type": "italics", "content": ["Felis catus"]},
  "), are small, ",
  {"type": "link", "to": "carnivore", "content": ["carnivorous"]},
  " ",
  {"type": "link", "to": "mammal", "content": ["mammals"]}
]
```

## Getting plain text content

```javascript
import {astToText} from 'wikiparse';

console.log(astToText(ast));
```

```
Cats, also called domestic cats (Felis catus), are small, carnivorous mammals
```

## Parsing a Wikipedia article

```javascript
import fetch from 'node-fetch';
import WikiParser, {astToText} from 'wikiparse';

const wiki = 'simple';
const page = 'Cat';
const url = `https://${wiki}.wikipedia.org/w/api.php?&action=query&titles=${encodeURIComponent(page)}&prop=revisions&rvprop=content&format=json`;
// If you need lots of pages, use XML dumps from https://dumps.wikimedia.org/
const json = await (await fetch(url)).json();
const source = Object.entries(json.query.pages)[0][1].revisions[0]['*'];

const parser = new WikiParser();
const ast = parser.parse(source);
console.log(JSON.stringify(ast, null, 2));
console.log(astToText(ast));

```

Output: [JSON](https://gist.github.com/yuryshulaev/1357f8b2a1d0a3a6890a4ada953f544c), [Text](https://gist.github.com/yuryshulaev/257a3900f825ea0b72f88e0fc8b70a1a).

## Importing Wikipedia dumps

You can use [wiki-import](https://github.com/yuryshulaev/wiki-import) to parse and import a whole Wikipedia dump into LevelDB (or something else with minor code modifications).

---
_Source: https://npm.io/package/wikiparse · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
