mirror of
https://activitypub.software/TransFem-org/sfm-js
synced 2024-11-21 21:55:09 +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
|
||||
built
|
||||
package-lock.json
|
||||
|
||||
# editor
|
||||
.vscode
|
||||
|
||||
# app dir
|
||||
built
|
||||
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
|
||||
## Description
|
||||
A MFM parser made with PEG.js (In developing)
|
||||
A MFM parser implementation with PEG.js (In developing)
|
||||
|
||||
## Installation
|
||||
```
|
||||
|
@ -8,11 +8,12 @@ npm i mfm-parser-pegjs
|
|||
```
|
||||
|
||||
## Usage
|
||||
TypeScript:
|
||||
```ts
|
||||
import * as mfm from 'mfm-parser-pegjs';
|
||||
|
||||
// parse a MFM text
|
||||
const result = mfm.parse('good morning ***everyone!***');
|
||||
const result = mfm.parse('good morning ***everynyan!***');
|
||||
|
||||
// parse a MFM plain text
|
||||
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
|
||||
```
|
||||
|
||||
### 2. Build
|
||||
For production:
|
||||
### 2. Install packages
|
||||
```
|
||||
cd mfm-parser-pegjs
|
||||
npm i
|
||||
```
|
||||
|
||||
### 3. Build
|
||||
```
|
||||
npm run build
|
||||
```
|
||||
|
||||
For development:
|
||||
```
|
||||
npm run build-dev
|
||||
```
|
||||
|
||||
### Use Interactive interface
|
||||
### Use the interactive CLI parser
|
||||
```
|
||||
npm run parse
|
||||
```
|
||||
|
||||
## License
|
||||
This software is released under the [MIT License](LICENSE) unless otherwise noted.
|
||||
|
||||
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
|
||||
This software is released under the [MIT License](LICENSE).
|
||||
|
|
39
package.json
39
package.json
|
@ -1,17 +1,16 @@
|
|||
{
|
||||
"name": "mfm-parser-pegjs",
|
||||
"version": "0.2.0",
|
||||
"description": "A MFM parser made with PEG.js",
|
||||
"description": "A MFM parser implementation with PEG.js",
|
||||
"main": "./built/index.js",
|
||||
"scripts": {
|
||||
"build": "npm run tsc && npm run peg && npm run webpack",
|
||||
"build-dev": "npm run tsc && npm run peg-dev && npm run webpack-dev",
|
||||
"peg": "mkdirp ./built/parser && pegjs -o built/parser/core-parser.js --allowed-start-rules fullParser,inlineParser,plainParser src/parser/core-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",
|
||||
"build": "npm run tsc && npm run peg",
|
||||
"build-debug": "npm run tsc && npm run peg-debug",
|
||||
"peg": "pegjs -o built/parser.js --allowed-start-rules fullParser,inlineParser,plainParser src/parser.pegjs",
|
||||
"peg-debug": "pegjs -o built/parser.js --allowed-start-rules fullParser,inlineParser,plainParser --trace src/parser.pegjs",
|
||||
"tsc": "tsc",
|
||||
"webpack": "webpack --mode=production",
|
||||
"webpack-dev": "webpack --mode=development",
|
||||
"parse": "node ./built/parse"
|
||||
"parse": "node ./built/cli/parse",
|
||||
"test": "mocha -r ts-node/register 'test/**/*.ts'"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
@ -20,20 +19,18 @@
|
|||
"author": "Marihachi",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@types/node": "^12.0.4",
|
||||
"@types/parsimmon": "^1.10.1",
|
||||
"@types/pegjs": "^0.10.1",
|
||||
"mkdirp": "^0.5.1",
|
||||
"parsimmon": "^1.13.0",
|
||||
"pegjs": "^0.10.0",
|
||||
"ts-loader": "6.2.x",
|
||||
"typescript": "3.7.x",
|
||||
"webpack": "4.40.x",
|
||||
"webpack-cli": "3.3.x"
|
||||
"@types/mocha": "8.2.x",
|
||||
"@types/node": "14.14.x",
|
||||
"@types/pegjs": "0.10.x",
|
||||
"mocha": "8.3.x",
|
||||
"pegjs": "0.10.x",
|
||||
"ts-node": "9.1.x",
|
||||
"typescript": "4.2.x"
|
||||
},
|
||||
"dependencies": {
|
||||
"twemoji-parser": "13.0.x"
|
||||
},
|
||||
"files": [
|
||||
"built/index.js",
|
||||
"built/index.d.ts",
|
||||
"built/parser"
|
||||
"built"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import inputLine, { InputCanceledError } from './misc/inputLine';
|
||||
import { parse } from './parser/index';
|
||||
import { parse } from '..';
|
||||
|
||||
async function entryPoint() {
|
||||
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
|
||||
|
||||
const emojiRegex = require('./twemoji').default;
|
||||
const emojiRegex = require('twemoji-parser/dist/lib/regex').default;
|
||||
|
||||
let emojiLoop = 0;
|
||||
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": [
|
||||
"node_modules",
|
||||
"src/client/**/*",
|
||||
"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