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
4fe75b13
Commit
4fe75b13
authored
3 years ago
by
marihachi
Browse files
Options
Downloads
Patches
Plain Diff
wip
parent
ae2296d6
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
+17
-25
17 additions, 25 deletions
src/util.ts
with
18 additions
and
26 deletions
src/parser.pegjs
+
1
−
1
View file @
4fe75b13
...
...
@@ -386,7 +386,7 @@ fnArg
// inline: text
text
= .
{ return createNode('text', { text: text() }); }
= .
//
// General
...
...
This diff is collapsed.
Click to expand it.
src/util.ts
+
17
−
25
View file @
4fe75b13
...
...
@@ -30,45 +30,37 @@ export function groupContinuous<T>(arr: T[], predicate: (prev: T, current: T) =>
return
dest
;
}
export
function
mergeGroupedTrees
(
groupedTrees
:
MfmNode
[][]):
MfmNode
[]
{
return
groupedTrees
.
reduce
((
acc
,
val
)
=>
acc
.
concat
(
val
),
([]
as
MfmNode
[]));
export
function
mergeGroupedTrees
<
T
>
(
groupedTrees
:
T
[][]):
T
[]
{
return
groupedTrees
.
reduce
((
acc
,
val
)
=>
acc
.
concat
(
val
),
([]
as
T
[]));
}
export
function
mergeText
(
trees
:
MfmNode
[]
|
undefined
,
recursive
?:
boolean
):
MfmNode
[]
|
undefined
{
let
dest
:
MfmNode
[];
let
groupes
:
MfmNode
[][];
if
(
trees
==
null
)
{
return
trees
;
}
export
function
mergeText
(
trees
:
(
MfmNode
|
string
)[]):
MfmNode
[]
{
// group trees
groupes
=
groupContinuous
(
trees
,
(
prev
,
current
)
=>
prev
.
type
==
current
.
type
);
const
groupes
=
groupContinuous
(
trees
,
(
prev
,
current
)
=>
{
if
(
typeof
prev
==
'
string
'
||
typeof
current
==
'
string
'
)
{
return
(
typeof
prev
==
'
string
'
&&
typeof
current
==
'
string
'
);
}
else
{
return
(
prev
.
type
==
current
.
type
);
}
});
// concatinate text
g
roupes
=
groupes
.
map
((
group
)
=>
{
if
(
group
[
0
]
.
type
==
'
text
'
)
{
const
concatG
roupes
=
groupes
.
map
((
group
)
=>
{
if
(
typeof
group
[
0
]
==
'
string
'
)
{
return
[
createNode
(
'
text
'
,
{
text
:
group
.
map
(
i
=>
(
i
as
MfmText
).
props
.
text
).
join
(
''
)
text
:
(
group
as
string
[]
).
join
(
''
)
})
];
}
return
group
;
return
(
group
as
MfmNode
[])
;
});
// merge groups
dest
=
mergeGroupedTrees
(
g
roupes
);
const
dest
=
mergeGroupedTrees
(
concatG
roupes
);
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
;
}
return
dest
;
}
export
function
stringifyNode
(
node
:
MfmNode
):
string
{
...
...
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