Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
sfm-js
Manage
Activity
Members
Labels
Plan
Issues
2
Issue boards
Milestones
Iterations
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
TransFem.org
sfm-js
Commits
cbb00a5a
Commit
cbb00a5a
authored
3 years ago
by
marihachi
Browse files
Options
Downloads
Patches
Plain Diff
export node generation macros.
parent
33c0b6c9
No related branches found
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
src/index.ts
+29
-3
29 additions, 3 deletions
src/index.ts
src/node.ts
+19
-0
19 additions, 0 deletions
src/node.ts
test/api.ts
+1
-1
1 addition, 1 deletion
test/api.ts
test/node.ts
+0
-24
0 additions, 24 deletions
test/node.ts
test/parser.ts
+7
-26
7 additions, 26 deletions
test/parser.ts
with
56 additions
and
54 deletions
src/index.ts
+
29
−
3
View file @
cbb00a5a
...
...
@@ -6,13 +6,14 @@ export {
extract
}
from
'
./api
'
;
export
{
NodeType
}
from
'
./node
'
;
export
{
NodeType
,
MfmNode
,
MfmBlock
,
MfmInline
,
MfmInline
}
from
'
./node
'
;
export
{
// block
MfmQuote
,
MfmSearch
,
...
...
@@ -36,3 +37,28 @@ export {
MfmFn
,
MfmText
}
from
'
./node
'
;
export
{
// block
QUOTE
,
SEARCH
,
CODE_BLOCK
,
MATH_BLOCK
,
CENTER
,
// inline
UNI_EMOJI
,
EMOJI_CODE
,
BOLD
,
SMALL
,
ITALIC
,
STRIKE
,
INLINE_CODE
,
MATH_INLINE
,
MENTION
,
HASHTAG
,
N_URL
,
LINK
,
FN
,
TEXT
}
from
'
./node
'
;
This diff is collapsed.
Click to expand it.
src/node.ts
+
19
−
0
View file @
cbb00a5a
...
...
@@ -14,6 +14,7 @@ export type MfmQuote = {
props
?:
{
};
children
:
MfmNode
[];
};
export
const
QUOTE
=
(
children
:
MfmNode
[]):
NodeType
<
'
quote
'
>
=>
{
return
{
type
:
'
quote
'
,
children
};
};
export
type
MfmSearch
=
{
type
:
'
search
'
;
...
...
@@ -23,6 +24,7 @@ export type MfmSearch = {
};
children
?:
[];
};
export
const
SEARCH
=
(
query
:
string
,
content
:
string
):
NodeType
<
'
search
'
>
=>
{
return
{
type
:
'
search
'
,
props
:
{
query
,
content
}
};
};
export
type
MfmCodeBlock
=
{
type
:
'
blockCode
'
;
...
...
@@ -32,6 +34,7 @@ export type MfmCodeBlock = {
};
children
?:
[];
};
export
const
CODE_BLOCK
=
(
code
:
string
,
lang
:
string
|
null
):
NodeType
<
'
blockCode
'
>
=>
{
return
{
type
:
'
blockCode
'
,
props
:
{
code
,
lang
}
};
};
export
type
MfmMathBlock
=
{
type
:
'
mathBlock
'
;
...
...
@@ -40,12 +43,14 @@ export type MfmMathBlock = {
};
children
?:
[];
};
export
const
MATH_BLOCK
=
(
formula
:
string
):
NodeType
<
'
mathBlock
'
>
=>
{
return
{
type
:
'
mathBlock
'
,
props
:
{
formula
}
};
};
export
type
MfmCenter
=
{
type
:
'
center
'
;
props
?:
{
};
children
:
MfmInline
[];
};
export
const
CENTER
=
(
children
:
MfmInline
[]):
NodeType
<
'
center
'
>
=>
{
return
{
type
:
'
center
'
,
children
};
};
export
type
MfmInline
=
MfmUnicodeEmoji
|
MfmEmojiCode
|
MfmBold
|
MfmSmall
|
MfmItalic
|
MfmStrike
|
MfmInlineCode
|
MfmMathInline
|
MfmMention
|
MfmHashtag
|
MfmUrl
|
MfmLink
|
MfmFn
|
MfmText
;
...
...
@@ -57,6 +62,7 @@ export type MfmUnicodeEmoji = {
};
children
?:
[];
};
export
const
UNI_EMOJI
=
(
value
:
string
):
NodeType
<
'
unicodeEmoji
'
>
=>
{
return
{
type
:
'
unicodeEmoji
'
,
props
:
{
emoji
:
value
}
};
};
export
type
MfmEmojiCode
=
{
type
:
'
emojiCode
'
;
...
...
@@ -65,30 +71,35 @@ export type MfmEmojiCode = {
};
children
?:
[];
};
export
const
EMOJI_CODE
=
(
name
:
string
):
NodeType
<
'
emojiCode
'
>
=>
{
return
{
type
:
'
emojiCode
'
,
props
:
{
name
:
name
}
};
};
export
type
MfmBold
=
{
type
:
'
bold
'
;
props
?:
{
};
children
:
MfmInline
[];
};
export
const
BOLD
=
(
children
:
MfmInline
[]):
NodeType
<
'
bold
'
>
=>
{
return
{
type
:
'
bold
'
,
children
};
};
export
type
MfmSmall
=
{
type
:
'
small
'
;
props
?:
{
};
children
:
MfmInline
[];
};
export
const
SMALL
=
(
children
:
MfmInline
[]):
NodeType
<
'
small
'
>
=>
{
return
{
type
:
'
small
'
,
children
};
};
export
type
MfmItalic
=
{
type
:
'
italic
'
;
props
?:
{
};
children
:
MfmInline
[];
};
export
const
ITALIC
=
(
children
:
MfmInline
[]):
NodeType
<
'
italic
'
>
=>
{
return
{
type
:
'
italic
'
,
children
};
};
export
type
MfmStrike
=
{
type
:
'
strike
'
;
props
?:
{
};
children
:
MfmInline
[];
};
export
const
STRIKE
=
(
children
:
MfmInline
[]):
NodeType
<
'
strike
'
>
=>
{
return
{
type
:
'
strike
'
,
children
};
};
export
type
MfmInlineCode
=
{
type
:
'
inlineCode
'
;
...
...
@@ -97,6 +108,7 @@ export type MfmInlineCode = {
};
children
?:
[];
};
export
const
INLINE_CODE
=
(
code
:
string
):
NodeType
<
'
inlineCode
'
>
=>
{
return
{
type
:
'
inlineCode
'
,
props
:
{
code
}
};
};
export
type
MfmMathInline
=
{
type
:
'
mathInline
'
;
...
...
@@ -105,6 +117,7 @@ export type MfmMathInline = {
};
children
?:
[];
};
export
const
MATH_INLINE
=
(
formula
:
string
):
NodeType
<
'
mathInline
'
>
=>
{
return
{
type
:
'
mathInline
'
,
props
:
{
formula
}
};
};
export
type
MfmMention
=
{
type
:
'
mention
'
;
...
...
@@ -115,6 +128,7 @@ export type MfmMention = {
};
children
?:
[];
};
export
const
MENTION
=
(
username
:
string
,
host
:
string
|
null
,
acct
:
string
):
NodeType
<
'
mention
'
>
=>
{
return
{
type
:
'
mention
'
,
props
:
{
username
,
host
,
acct
}
};
};
export
type
MfmHashtag
=
{
type
:
'
hashtag
'
;
...
...
@@ -123,6 +137,7 @@ export type MfmHashtag = {
};
children
?:
[];
};
export
const
HASHTAG
=
(
value
:
string
):
NodeType
<
'
hashtag
'
>
=>
{
return
{
type
:
'
hashtag
'
,
props
:
{
hashtag
:
value
}
};
};
export
type
MfmUrl
=
{
type
:
'
url
'
;
...
...
@@ -131,6 +146,7 @@ export type MfmUrl = {
};
children
?:
[];
};
export
const
N_URL
=
(
value
:
string
):
NodeType
<
'
url
'
>
=>
{
return
{
type
:
'
url
'
,
props
:
{
url
:
value
}
};
};
export
type
MfmLink
=
{
type
:
'
link
'
;
...
...
@@ -140,6 +156,7 @@ export type MfmLink = {
};
children
:
MfmInline
[];
};
export
const
LINK
=
(
silent
:
boolean
,
url
:
string
,
children
:
MfmInline
[]):
NodeType
<
'
link
'
>
=>
{
return
{
type
:
'
link
'
,
props
:
{
silent
,
url
},
children
};
};
export
type
MfmFn
=
{
type
:
'
fn
'
;
...
...
@@ -149,6 +166,7 @@ export type MfmFn = {
};
children
:
MfmInline
[];
};
export
const
FN
=
(
name
:
string
,
args
:
MfmFn
[
'
props
'
][
'
args
'
],
children
:
MfmFn
[
'
children
'
]):
NodeType
<
'
fn
'
>
=>
{
return
{
type
:
'
fn
'
,
props
:
{
name
,
args
},
children
};
};
export
type
MfmText
=
{
type
:
'
text
'
;
...
...
@@ -157,6 +175,7 @@ export type MfmText = {
};
children
?:
[];
};
export
const
TEXT
=
(
value
:
string
):
NodeType
<
'
text
'
>
=>
{
return
{
type
:
'
text
'
,
props
:
{
text
:
value
}
};
};
export
type
NodeType
<
T
extends
MfmNode
[
'
type
'
]
>
=
T
extends
'
quote
'
?
MfmQuote
:
...
...
This diff is collapsed.
Click to expand it.
test/api.ts
+
1
−
1
View file @
cbb00a5a
...
...
@@ -2,7 +2,7 @@ import assert from 'assert';
import
*
as
mfm
from
'
../built/index
'
;
import
{
TEXT
,
CENTER
,
FN
,
UNI_EMOJI
,
MENTION
,
EMOJI_CODE
,
HASHTAG
,
N_URL
,
BOLD
,
SMALL
,
ITALIC
,
STRIKE
,
QUOTE
,
MATH_BLOCK
,
SEARCH
,
CODE_BLOCK
,
LINK
}
from
'
.
/no
de
'
;
}
from
'
.
./built/in
de
x
'
;
describe
(
'
API
'
,
()
=>
{
describe
(
'
toString
'
,
()
=>
{
...
...
This diff is collapsed.
Click to expand it.
test/node.ts
deleted
100644 → 0
+
0
−
24
View file @
33c0b6c9
import
{
MfmFn
,
MfmInline
,
MfmNode
,
NodeType
}
from
'
../built
'
;
export
const
QUOTE
=
(
children
:
MfmNode
[]):
NodeType
<
'
quote
'
>
=>
{
return
{
type
:
'
quote
'
,
children
};
};
export
const
SEARCH
=
(
query
:
string
,
content
:
string
):
NodeType
<
'
search
'
>
=>
{
return
{
type
:
'
search
'
,
props
:
{
query
,
content
}
};
};
export
const
CODE_BLOCK
=
(
code
:
string
,
lang
:
string
|
null
):
NodeType
<
'
blockCode
'
>
=>
{
return
{
type
:
'
blockCode
'
,
props
:
{
code
,
lang
}
};
};
export
const
MATH_BLOCK
=
(
formula
:
string
):
NodeType
<
'
mathBlock
'
>
=>
{
return
{
type
:
'
mathBlock
'
,
props
:
{
formula
}
};
};
export
const
CENTER
=
(
children
:
MfmInline
[]):
NodeType
<
'
center
'
>
=>
{
return
{
type
:
'
center
'
,
children
};
};
export
const
BOLD
=
(
children
:
MfmInline
[]):
NodeType
<
'
bold
'
>
=>
{
return
{
type
:
'
bold
'
,
children
};
};
export
const
SMALL
=
(
children
:
MfmInline
[]):
NodeType
<
'
small
'
>
=>
{
return
{
type
:
'
small
'
,
children
};
};
export
const
ITALIC
=
(
children
:
MfmInline
[]):
NodeType
<
'
italic
'
>
=>
{
return
{
type
:
'
italic
'
,
children
};
};
export
const
STRIKE
=
(
children
:
MfmInline
[]):
NodeType
<
'
strike
'
>
=>
{
return
{
type
:
'
strike
'
,
children
};
};
export
const
INLINE_CODE
=
(
code
:
string
):
NodeType
<
'
inlineCode
'
>
=>
{
return
{
type
:
'
inlineCode
'
,
props
:
{
code
}
};
};
export
const
MATH_INLINE
=
(
formula
:
string
):
NodeType
<
'
mathInline
'
>
=>
{
return
{
type
:
'
mathInline
'
,
props
:
{
formula
}
};
};
export
const
MENTION
=
(
username
:
string
,
host
:
string
|
null
,
acct
:
string
):
NodeType
<
'
mention
'
>
=>
{
return
{
type
:
'
mention
'
,
props
:
{
username
,
host
,
acct
}
};
};
export
const
HASHTAG
=
(
value
:
string
):
NodeType
<
'
hashtag
'
>
=>
{
return
{
type
:
'
hashtag
'
,
props
:
{
hashtag
:
value
}
};
};
export
const
N_URL
=
(
value
:
string
):
NodeType
<
'
url
'
>
=>
{
return
{
type
:
'
url
'
,
props
:
{
url
:
value
}
};
};
export
const
LINK
=
(
silent
:
boolean
,
url
:
string
,
children
:
MfmInline
[]):
NodeType
<
'
link
'
>
=>
{
return
{
type
:
'
link
'
,
props
:
{
silent
,
url
},
children
};
};
export
const
EMOJI_CODE
=
(
name
:
string
):
NodeType
<
'
emojiCode
'
>
=>
{
return
{
type
:
'
emojiCode
'
,
props
:
{
name
:
name
}
};
};
export
const
FN
=
(
name
:
string
,
args
:
MfmFn
[
'
props
'
][
'
args
'
],
children
:
MfmFn
[
'
children
'
]):
NodeType
<
'
fn
'
>
=>
{
return
{
type
:
'
fn
'
,
props
:
{
name
,
args
},
children
};
};
export
const
UNI_EMOJI
=
(
value
:
string
):
NodeType
<
'
unicodeEmoji
'
>
=>
{
return
{
type
:
'
unicodeEmoji
'
,
props
:
{
emoji
:
value
}
};
};
export
const
TEXT
=
(
value
:
string
):
NodeType
<
'
text
'
>
=>
{
return
{
type
:
'
text
'
,
props
:
{
text
:
value
}
};
};
This diff is collapsed.
Click to expand it.
test/parser.ts
+
7
−
26
View file @
cbb00a5a
import
assert
from
'
assert
'
;
import
*
as
mfm
from
'
../built/index
'
;
import
{
createNode
}
from
'
../built/util
'
;
import
{
TEXT
,
CENTER
,
FN
,
UNI_EMOJI
,
MENTION
,
EMOJI_CODE
,
HASHTAG
,
N_URL
,
BOLD
,
SMALL
,
ITALIC
,
STRIKE
,
QUOTE
,
MATH_BLOCK
,
SEARCH
,
CODE_BLOCK
,
LINK
}
from
'
.
/no
de
'
;
}
from
'
.
./built/in
de
x
'
;
describe
(
'
parser
'
,
()
=>
{
describe
(
'
text
'
,
()
=>
{
...
...
@@ -75,60 +74,42 @@ describe('parser', () => {
it
(
'
Search
'
,
()
=>
{
const
input
=
'
MFM 書き方 123 Search
'
;
const
output
=
[
createNode
(
'
search
'
,
{
query
:
'
MFM 書き方 123
'
,
content
:
input
})
SEARCH
(
'
MFM 書き方 123
'
,
input
)
];
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
it
(
'
[Search]
'
,
()
=>
{
const
input
=
'
MFM 書き方 123 [Search]
'
;
const
output
=
[
createNode
(
'
search
'
,
{
query
:
'
MFM 書き方 123
'
,
content
:
input
})
SEARCH
(
'
MFM 書き方 123
'
,
input
)
];
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
it
(
'
search
'
,
()
=>
{
const
input
=
'
MFM 書き方 123 search
'
;
const
output
=
[
createNode
(
'
search
'
,
{
query
:
'
MFM 書き方 123
'
,
content
:
input
})
SEARCH
(
'
MFM 書き方 123
'
,
input
)
];
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
it
(
'
[search]
'
,
()
=>
{
const
input
=
'
MFM 書き方 123 [search]
'
;
const
output
=
[
createNode
(
'
search
'
,
{
query
:
'
MFM 書き方 123
'
,
content
:
input
})
SEARCH
(
'
MFM 書き方 123
'
,
input
)
];
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
it
(
'
検索
'
,
()
=>
{
const
input
=
'
MFM 書き方 123 検索
'
;
const
output
=
[
createNode
(
'
search
'
,
{
query
:
'
MFM 書き方 123
'
,
content
:
input
})
SEARCH
(
'
MFM 書き方 123
'
,
input
)
];
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
it
(
'
[検索]
'
,
()
=>
{
const
input
=
'
MFM 書き方 123 [検索]
'
;
const
output
=
[
createNode
(
'
search
'
,
{
query
:
'
MFM 書き方 123
'
,
content
:
input
})
SEARCH
(
'
MFM 書き方 123
'
,
input
)
];
assert
.
deepStrictEqual
(
mfm
.
parse
(
input
),
output
);
});
...
...
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