Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
sfm-js
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dakkar
sfm-js
Commits
0182d2ca
Commit
0182d2ca
authored
4 years ago
by
marihachi
Browse files
Options
Downloads
Patches
Plain Diff
add type definition of MFM nodes.
parent
1c396215
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/cli/parse.ts
+1
-2
1 addition, 2 deletions
src/cli/parse.ts
src/index.ts
+29
-1
29 additions, 1 deletion
src/index.ts
src/node.ts
+144
-0
144 additions, 0 deletions
src/node.ts
src/util.ts
+3
-7
3 additions, 7 deletions
src/util.ts
with
177 additions
and
10 deletions
src/cli/parse.ts
+
1
−
2
View file @
0182d2ca
...
...
@@ -23,9 +23,8 @@ async function entryPoint() {
.
replace
(
/
\\
t/g
,
'
\t
'
)
.
replace
(
/
\\
u00a0/g
,
'
\
u00a0
'
);
let
result
:
any
;
try
{
result
=
parse
(
input
);
const
result
=
parse
(
input
);
console
.
log
(
JSON
.
stringify
(
result
));
}
catch
(
err
)
{
...
...
This diff is collapsed.
Click to expand it.
src/index.ts
+
29
−
1
View file @
0182d2ca
import
peg
from
'
pegjs
'
;
import
{
MfmNode
}
from
'
./
util
'
;
import
{
MfmNode
}
from
'
./
node
'
;
const
parser
:
peg
.
Parser
=
require
(
'
./parser
'
);
export
function
parse
(
input
:
string
):
MfmNode
[]
{
...
...
@@ -11,3 +11,31 @@ export function parsePlain(input: string): MfmNode[] {
const
nodes
=
parser
.
parse
(
input
,
{
startRule
:
'
plainParser
'
});
return
nodes
;
}
export
{
MfmNode
,
MfmBlock
,
MfmInline
,
// block
MfmQuote
,
MfmSearch
,
MfmCodeBlock
,
MfmMathBlock
,
MfmCenter
,
// inline
MfmEmoji
,
MfmBold
,
MfmSmall
,
MfmItalic
,
MfmStrike
,
MfmInlineCode
,
MfmMathInline
,
MfmMention
,
MfmHashtag
,
MfmUrl
,
MfmLink
,
MfmFn
,
MfmText
}
from
'
./node
'
;
This diff is collapsed.
Click to expand it.
src/node.ts
0 → 100644
+
144
−
0
View file @
0182d2ca
export
type
MfmNode
=
MfmBlock
|
MfmInline
;
export
type
MfmBlock
=
MfmQuote
|
MfmSearch
|
MfmCodeBlock
|
MfmMathBlock
|
MfmCenter
;
export
type
MfmQuote
=
{
type
:
'
quote
'
;
props
:
{
};
children
:
MfmNode
[];
};
export
type
MfmSearch
=
{
type
:
'
search
'
;
props
:
{
q
:
string
;
content
:
string
;
};
children
:
[];
};
export
type
MfmCodeBlock
=
{
type
:
'
blockCode
'
;
props
:
{
code
:
string
;
lang
:
string
|
null
;
};
children
:
[];
};
export
type
MfmMathBlock
=
{
type
:
'
mathBlock
'
;
props
:
{
formula
:
string
;
};
children
:
[];
};
export
type
MfmCenter
=
{
type
:
'
center
'
;
props
:
{
};
children
:
MfmNode
[];
};
export
type
MfmInline
=
MfmEmoji
|
MfmBold
|
MfmSmall
|
MfmItalic
|
MfmStrike
|
MfmInlineCode
|
MfmMathInline
|
MfmMention
|
MfmHashtag
|
MfmUrl
|
MfmLink
|
MfmFn
|
MfmText
;
export
type
MfmEmoji
=
{
type
:
'
emoji
'
;
props
:
{
emoji
:
string
;
name
:
undefined
;
}
|
{
emoji
:
undefined
;
name
:
string
;
};
children
:
[];
};
export
type
MfmBold
=
{
type
:
'
bold
'
;
props
:
{
};
children
:
MfmInline
[];
};
export
type
MfmSmall
=
{
type
:
'
small
'
;
props
:
{
};
children
:
MfmInline
[];
};
export
type
MfmItalic
=
{
type
:
'
italic
'
;
props
:
{
};
children
:
MfmInline
[];
};
export
type
MfmStrike
=
{
type
:
'
strike
'
;
props
:
{
};
children
:
MfmInline
[];
};
export
type
MfmInlineCode
=
{
type
:
'
inlineCode
'
;
props
:
{
code
:
string
;
};
children
:
[];
};
export
type
MfmMathInline
=
{
type
:
'
mathInline
'
;
props
:
{
formula
:
string
;
};
children
:
[];
};
export
type
MfmMention
=
{
type
:
'
mention
'
;
props
:
{
username
:
string
;
host
:
string
|
null
;
acct
:
string
;
};
children
:
[];
};
export
type
MfmHashtag
=
{
type
:
'
hashtag
'
;
props
:
{
hashtag
:
string
;
};
children
:
[];
};
export
type
MfmUrl
=
{
type
:
'
url
'
;
props
:
{
url
:
string
;
};
children
:
[];
};
export
type
MfmLink
=
{
type
:
'
link
'
;
props
:
{
silent
:
boolean
;
url
:
string
;
};
children
:
MfmInline
[];
};
export
type
MfmFn
=
{
type
:
'
fn
'
;
props
:
{
name
:
string
;
args
:
Record
<
string
,
string
|
true
>
;
};
children
:
MfmInline
[];
};
export
type
MfmText
=
{
type
:
'
text
'
;
props
:
{
text
:
string
;
};
children
:
[];
};
This diff is collapsed.
Click to expand it.
src/util.ts
+
3
−
7
View file @
0182d2ca
export
type
MfmNode
=
{
type
:
string
;
props
:
Record
<
string
,
any
>
;
children
:
MfmNode
[];
};
import
{
MfmNode
,
MfmText
}
from
'
./node
'
;
export
function
createNode
(
type
:
string
,
props
?:
Record
<
string
,
any
>
,
children
?:
MfmNode
[]):
MfmNode
{
props
=
props
??
{};
children
=
children
??
[];
const
node
=
{
type
,
props
,
children
};
const
node
=
{
type
,
props
,
children
}
as
MfmNode
;
return
node
;
}
...
...
@@ -46,7 +42,7 @@ export function mergeText(trees: MfmNode[], recursive?: boolean): MfmNode[] {
if
(
group
[
0
].
type
==
'
text
'
)
{
return
[
createNode
(
'
text
'
,
{
text
:
group
.
map
(
i
=>
i
.
props
.
text
).
join
(
''
)
text
:
group
.
map
(
i
=>
(
i
as
MfmText
)
.
props
.
text
).
join
(
''
)
})
];
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment