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
e06ff15a
Commit
e06ff15a
authored
4 years ago
by
marihachi
Browse files
Options
Downloads
Plain Diff
Merge branch 'work-32' into develop
parents
985e2ab9
d95206fe
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/parser.pegjs
+1
-1
1 addition, 1 deletion
src/parser.pegjs
src/util.ts
+22
-52
22 additions, 52 deletions
src/util.ts
with
23 additions
and
53 deletions
src/parser.pegjs
+
1
−
1
View file @
e06ff15a
...
@@ -386,7 +386,7 @@ fnArg
...
@@ -386,7 +386,7 @@ fnArg
// inline: text
// inline: text
text
text
= .
{ return createNode('text', { text: text() }); }
= .
//
//
// General
// General
...
...
This diff is collapsed.
Click to expand it.
src/util.ts
+
22
−
52
View file @
e06ff15a
import
{
MfmNode
,
MfmText
}
from
'
./node
'
;
import
{
MfmNode
}
from
'
./node
'
;
export
function
createNode
(
type
:
string
,
props
?:
Record
<
string
,
any
>
,
children
?:
MfmNode
[]):
MfmNode
{
export
function
createNode
(
type
:
string
,
props
?:
Record
<
string
,
any
>
,
children
?:
MfmNode
[]):
MfmNode
{
const
node
:
any
=
{
type
};
const
node
:
any
=
{
type
};
...
@@ -11,66 +11,36 @@ export function createNode(type: string, props?: Record<string, any>, children?:
...
@@ -11,66 +11,36 @@ export function createNode(type: string, props?: Record<string, any>, children?:
return
node
;
return
node
;
}
}
/**
export
function
mergeText
(
nodes
:
(
MfmNode
|
string
)[]):
MfmNode
[]
{
* @param predicate specifies whether to group the previous item and the current item
const
dest
:
MfmNode
[]
=
[];
* @returns grouped items
const
storedChars
:
string
[]
=
[];
*/
export
function
groupContinuous
<
T
>
(
arr
:
T
[],
predicate
:
(
prev
:
T
,
current
:
T
)
=>
boolean
):
T
[][]
{
/**
const
dest
:
any
[][]
=
[];
* Generate a text node from the stored chars, And push it.
*/
function
generateText
()
{
if
(
storedChars
.
length
>
0
)
{
const
textNode
=
createNode
(
'
text
'
,
{
text
:
storedChars
.
join
(
''
)
});
dest
.
push
(
textNode
);
storedChars
.
length
=
0
;
}
}
for
(
let
i
=
0
;
i
<
arr
.
length
;
i
++
)
{
for
(
const
node
of
nodes
)
{
if
(
i
!=
0
&&
predicate
(
arr
[
i
-
1
],
arr
[
i
]))
{
if
(
typeof
node
==
'
string
'
)
{
dest
[
dest
.
length
-
1
].
push
(
arr
[
i
]);
// Store the char.
storedChars
.
push
(
node
);
}
}
else
{
else
{
dest
.
push
([
arr
[
i
]]);
generateText
();
dest
.
push
(
node
);
}
}
}
}
generateText
();
return
dest
;
return
dest
;
}
}
export
function
mergeGroupedTrees
(
groupedTrees
:
MfmNode
[][]):
MfmNode
[]
{
return
groupedTrees
.
reduce
((
acc
,
val
)
=>
acc
.
concat
(
val
),
([]
as
MfmNode
[]));
}
export
function
mergeText
(
trees
:
MfmNode
[]
|
undefined
,
recursive
?:
boolean
):
MfmNode
[]
|
undefined
{
let
dest
:
MfmNode
[];
let
groupes
:
MfmNode
[][];
if
(
trees
==
null
)
{
return
trees
;
}
// group trees
groupes
=
groupContinuous
(
trees
,
(
prev
,
current
)
=>
prev
.
type
==
current
.
type
);
// concatinate text
groupes
=
groupes
.
map
((
group
)
=>
{
if
(
group
[
0
].
type
==
'
text
'
)
{
return
[
createNode
(
'
text
'
,
{
text
:
group
.
map
(
i
=>
(
i
as
MfmText
).
props
.
text
).
join
(
''
)
})
];
}
return
group
;
});
// merge groups
dest
=
mergeGroupedTrees
(
groupes
);
if
(
recursive
)
{
return
dest
.
map
(
tree
=>
{
// apply recursively to children
return
createNode
(
tree
.
type
,
tree
.
props
,
recursive
?
mergeText
(
tree
.
children
)
:
tree
.
children
);
});
}
else
{
return
dest
;
}
}
export
function
stringifyNode
(
node
:
MfmNode
):
string
{
export
function
stringifyNode
(
node
:
MfmNode
):
string
{
switch
(
node
.
type
)
{
switch
(
node
.
type
)
{
// block
// block
...
...
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