mirror of
https://activitypub.software/TransFem-org/sfm-js
synced 2024-11-28 17:03:03 +00:00
update iroiro
This commit is contained in:
parent
7316896019
commit
0f15119c40
16 changed files with 52 additions and 148 deletions
8
.gitignore
vendored
8
.gitignore
vendored
|
@ -1,6 +1,10 @@
|
||||||
|
# npm
|
||||||
node_modules
|
node_modules
|
||||||
built
|
|
||||||
package-lock.json
|
package-lock.json
|
||||||
|
|
||||||
|
# editor
|
||||||
|
.vscode
|
||||||
|
|
||||||
|
# app dir
|
||||||
|
built
|
||||||
temp
|
temp
|
||||||
syuilo-*
|
|
||||||
|
|
1
.npmignore
Normal file
1
.npmignore
Normal file
|
@ -0,0 +1 @@
|
||||||
|
built/debug
|
28
README.md
28
README.md
|
@ -1,6 +1,6 @@
|
||||||
# mfm-parser-pegjs
|
# mfm-parser-pegjs
|
||||||
## Description
|
## Description
|
||||||
A MFM parser made with PEG.js (In developing)
|
A MFM parser implementation with PEG.js (In developing)
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
```
|
```
|
||||||
|
@ -8,11 +8,12 @@ npm i mfm-parser-pegjs
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
TypeScript:
|
||||||
```ts
|
```ts
|
||||||
import * as mfm from 'mfm-parser-pegjs';
|
import * as mfm from 'mfm-parser-pegjs';
|
||||||
|
|
||||||
// parse a MFM text
|
// parse a MFM text
|
||||||
const result = mfm.parse('good morning ***everyone!***');
|
const result = mfm.parse('good morning ***everynyan!***');
|
||||||
|
|
||||||
// parse a MFM plain text
|
// parse a MFM plain text
|
||||||
const plainResult = mfm.parsePlain('I like the hot soup :soup:');
|
const plainResult = mfm.parsePlain('I like the hot soup :soup:');
|
||||||
|
@ -24,26 +25,21 @@ const plainResult = mfm.parsePlain('I like the hot soup :soup:');
|
||||||
git clone https://github.com/marihachi/mfm-parser-pegjs.git
|
git clone https://github.com/marihachi/mfm-parser-pegjs.git
|
||||||
```
|
```
|
||||||
|
|
||||||
### 2. Build
|
### 2. Install packages
|
||||||
For production:
|
```
|
||||||
|
cd mfm-parser-pegjs
|
||||||
|
npm i
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. Build
|
||||||
```
|
```
|
||||||
npm run build
|
npm run build
|
||||||
```
|
```
|
||||||
|
|
||||||
For development:
|
### Use the interactive CLI parser
|
||||||
```
|
|
||||||
npm run build-dev
|
|
||||||
```
|
|
||||||
|
|
||||||
### Use Interactive interface
|
|
||||||
```
|
```
|
||||||
npm run parse
|
npm run parse
|
||||||
```
|
```
|
||||||
|
|
||||||
## License
|
## License
|
||||||
This software is released under the [MIT License](LICENSE) unless otherwise noted.
|
This software is released under the [MIT License](LICENSE).
|
||||||
|
|
||||||
This software includes code of therd party softwares below:
|
|
||||||
- twemoji-parser
|
|
||||||
Copyright (c) 2018 Twitter, Inc.
|
|
||||||
MIT Licence: https://github.com/twitter/twemoji-parser/blob/master/LICENSE.md
|
|
||||||
|
|
39
package.json
39
package.json
|
@ -1,17 +1,16 @@
|
||||||
{
|
{
|
||||||
"name": "mfm-parser-pegjs",
|
"name": "mfm-parser-pegjs",
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"description": "A MFM parser made with PEG.js",
|
"description": "A MFM parser implementation with PEG.js",
|
||||||
"main": "./built/index.js",
|
"main": "./built/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "npm run tsc && npm run peg && npm run webpack",
|
"build": "npm run tsc && npm run peg",
|
||||||
"build-dev": "npm run tsc && npm run peg-dev && npm run webpack-dev",
|
"build-debug": "npm run tsc && npm run peg-debug",
|
||||||
"peg": "mkdirp ./built/parser && pegjs -o built/parser/core-parser.js --allowed-start-rules fullParser,inlineParser,plainParser src/parser/core-parser.pegjs",
|
"peg": "pegjs -o built/parser.js --allowed-start-rules fullParser,inlineParser,plainParser src/parser.pegjs",
|
||||||
"peg-dev": "mkdirp ./built/parser && pegjs -o built/parser/core-parser.js --allowed-start-rules fullParser,inlineParser,plainParser --trace src/parser/core-parser.pegjs",
|
"peg-debug": "pegjs -o built/parser.js --allowed-start-rules fullParser,inlineParser,plainParser --trace src/parser.pegjs",
|
||||||
"tsc": "tsc",
|
"tsc": "tsc",
|
||||||
"webpack": "webpack --mode=production",
|
"parse": "node ./built/cli/parse",
|
||||||
"webpack-dev": "webpack --mode=development",
|
"test": "mocha -r ts-node/register 'test/**/*.ts'"
|
||||||
"parse": "node ./built/parse"
|
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
@ -20,20 +19,18 @@
|
||||||
"author": "Marihachi",
|
"author": "Marihachi",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^12.0.4",
|
"@types/mocha": "8.2.x",
|
||||||
"@types/parsimmon": "^1.10.1",
|
"@types/node": "14.14.x",
|
||||||
"@types/pegjs": "^0.10.1",
|
"@types/pegjs": "0.10.x",
|
||||||
"mkdirp": "^0.5.1",
|
"mocha": "8.3.x",
|
||||||
"parsimmon": "^1.13.0",
|
"pegjs": "0.10.x",
|
||||||
"pegjs": "^0.10.0",
|
"ts-node": "9.1.x",
|
||||||
"ts-loader": "6.2.x",
|
"typescript": "4.2.x"
|
||||||
"typescript": "3.7.x",
|
},
|
||||||
"webpack": "4.40.x",
|
"dependencies": {
|
||||||
"webpack-cli": "3.3.x"
|
"twemoji-parser": "13.0.x"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"built/index.js",
|
"built"
|
||||||
"built/index.d.ts",
|
|
||||||
"built/parser"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import inputLine, { InputCanceledError } from './misc/inputLine';
|
import inputLine, { InputCanceledError } from './misc/inputLine';
|
||||||
import { parse } from './parser/index';
|
import { parse } from '..';
|
||||||
|
|
||||||
async function entryPoint() {
|
async function entryPoint() {
|
||||||
console.log('intaractive parser');
|
console.log('intaractive parser');
|
|
@ -1,10 +0,0 @@
|
||||||
import { parse } from '../../built/index';
|
|
||||||
|
|
||||||
async function entryPoint() {
|
|
||||||
const result = parse('abc');
|
|
||||||
console.log(JSON.stringify(result));
|
|
||||||
}
|
|
||||||
entryPoint()
|
|
||||||
.catch(err => {
|
|
||||||
console.log(err);
|
|
||||||
});
|
|
14
src/index.ts
14
src/index.ts
|
@ -1 +1,13 @@
|
||||||
export * from './parser';
|
import peg from 'pegjs';
|
||||||
|
import { MfmNode } from './mfm-node';
|
||||||
|
const parser: peg.Parser = require('./parser');
|
||||||
|
|
||||||
|
export function parse(input: string): MfmNode[] {
|
||||||
|
const nodes = parser.parse(input, { startRule: 'fullParser' });
|
||||||
|
return nodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function parsePlain(input: string): MfmNode[] {
|
||||||
|
const nodes = parser.parse(input, { startRule: 'plainParser' });
|
||||||
|
return nodes;
|
||||||
|
}
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
import { promises as fs } from 'fs';
|
|
||||||
import * as path from 'path';
|
|
||||||
import { parse } from './parser/index';
|
|
||||||
|
|
||||||
|
|
||||||
async function entryPoint() {
|
|
||||||
const input = await fs.readFile(path.join(__dirname, '../input.txt'), { encoding: 'utf-8' });
|
|
||||||
try {
|
|
||||||
console.log(JSON.stringify(parse(input)));
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
console.log(err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
entryPoint()
|
|
||||||
.catch(err => {
|
|
||||||
console.log(err);
|
|
||||||
process.exit(1);
|
|
||||||
});
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
// emoji
|
// emoji
|
||||||
|
|
||||||
const emojiRegex = require('./twemoji').default;
|
const emojiRegex = require('twemoji-parser/dist/lib/regex').default;
|
||||||
|
|
||||||
let emojiLoop = 0;
|
let emojiLoop = 0;
|
||||||
const anchoredEmojiRegex = RegExp(`^(?:${emojiRegex.source})`);
|
const anchoredEmojiRegex = RegExp(`^(?:${emojiRegex.source})`);
|
|
@ -1,15 +0,0 @@
|
||||||
import { MfmNode } from './mfm-node';
|
|
||||||
import peg from 'pegjs';
|
|
||||||
const coreParser: peg.Parser = require('./core-parser');
|
|
||||||
|
|
||||||
export function parse(input: string): MfmNode[] {
|
|
||||||
let nodes: MfmNode[];
|
|
||||||
nodes = coreParser.parse(input, { startRule: 'fullParser' });
|
|
||||||
return nodes;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function parsePlain(input: string): MfmNode[] {
|
|
||||||
let nodes: MfmNode[];
|
|
||||||
nodes = coreParser.parse(input, { startRule: 'plainParser' });
|
|
||||||
return nodes;
|
|
||||||
}
|
|
File diff suppressed because one or more lines are too long
|
@ -1,30 +0,0 @@
|
||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
/* Basic Options */
|
|
||||||
"target": "ES2015", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
|
|
||||||
"module": "ESNext",
|
|
||||||
"moduleResolution": "node",
|
|
||||||
"outDir": "./built/client/", /* Redirect output structure to the directory. */
|
|
||||||
"rootDir": "./src/", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
|
||||||
"removeComments": false,
|
|
||||||
|
|
||||||
/* Strict Type-Checking Options */
|
|
||||||
"strict": true, /* Enable all strict type-checking options. */
|
|
||||||
"strictFunctionTypes": true, /* Enable strict checking of function types. */
|
|
||||||
|
|
||||||
/* Additional Checks */
|
|
||||||
"noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
|
||||||
|
|
||||||
/* Module Resolution Options */
|
|
||||||
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
|
||||||
|
|
||||||
"experimentalDecorators": true,
|
|
||||||
},
|
|
||||||
"include": [
|
|
||||||
"src/**/*",
|
|
||||||
],
|
|
||||||
"exclude": [
|
|
||||||
"node_modules",
|
|
||||||
"test/**/*.ts",
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -23,7 +23,6 @@
|
||||||
],
|
],
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"node_modules",
|
"node_modules",
|
||||||
"src/client/**/*",
|
|
||||||
"test/**/*",
|
"test/**/*",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
module.exports = {
|
|
||||||
entry: './src/client/main-entry.ts',
|
|
||||||
output: {
|
|
||||||
path: `${__dirname}/built/client`,
|
|
||||||
publicPath: '/', // base path of URL
|
|
||||||
filename: 'bundle.js',
|
|
||||||
chunkFilename: "bundle.[name].js",
|
|
||||||
},
|
|
||||||
module: {
|
|
||||||
rules: [
|
|
||||||
{
|
|
||||||
test: /\.ts$/,
|
|
||||||
exclude: /node_modules/,
|
|
||||||
use: [
|
|
||||||
{
|
|
||||||
loader: 'ts-loader',
|
|
||||||
options: { configFile: 'tsconfig.client.json' },
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
]
|
|
||||||
},
|
|
||||||
resolve: {
|
|
||||||
extensions: ['.ts', '.js'],
|
|
||||||
},
|
|
||||||
};
|
|
Loading…
Reference in a new issue