Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
verona-modules-aspect
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository 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
IQB
verona-modules-aspect
Commits
ccb70e2c
Commit
ccb70e2c
authored
3 years ago
by
rhenck
Browse files
Options
Downloads
Patches
Plain Diff
[editor] Refactor cloze parser
parent
ce392fca
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
projects/editor/src/app/services/unit.service.ts
+1
-1
1 addition, 1 deletion
projects/editor/src/app/services/unit.service.ts
projects/editor/src/app/util/cloze-parser.ts
+7
-11
7 additions, 11 deletions
projects/editor/src/app/util/cloze-parser.ts
with
8 additions
and
12 deletions
projects/editor/src/app/services/unit.service.ts
+
1
−
1
View file @
ccb70e2c
...
...
@@ -256,7 +256,7 @@ export class UnitService {
this
.
idService
.
removeId
(
element
.
id
);
this
.
idService
.
addID
(
<
string
>
value
);
}
else
if
(
property
===
'
text
'
&&
element
.
type
===
'
cloze
'
)
{
element
.
setProperty
(
'
parts
'
,
ClozeParser
.
parse
(
value
as
string
,
this
.
idService
));
element
.
setProperty
(
'
parts
'
,
ClozeParser
.
createClozeParts
(
value
as
string
,
this
.
idService
));
}
else
{
element
.
setProperty
(
property
,
value
);
}
...
...
This diff is collapsed.
Click to expand it.
projects/editor/src/app/util/cloze-parser.ts
+
7
−
11
View file @
ccb70e2c
...
...
@@ -9,12 +9,8 @@ import { ToggleButtonElement } from '../../../../common/ui-elements/toggle-butto
import
{
IdService
}
from
'
../services/id.service
'
;
export
abstract
class
ClozeParser
{
static
parse
(
text
:
string
,
idService
:
IdService
):
ClozePart
[][]
{
return
ClozeParser
.
createParts
(
text
,
idService
);
}
private
static
createParts
(
htmlText
:
string
,
idService
:
IdService
):
ClozePart
[][]
{
const
elementList
=
ClozeParser
.
readElementArray
(
htmlText
);
static
createClozeParts
(
htmlText
:
string
,
idService
:
IdService
):
ClozePart
[][]
{
const
elementList
=
ClozeParser
.
createElementList
(
htmlText
);
const
parts
:
ClozePart
[][]
=
[];
elementList
.
forEach
((
element
:
HTMLParagraphElement
|
HTMLHeadingElement
,
i
:
number
)
=>
{
...
...
@@ -23,7 +19,7 @@ export abstract class ClozeParser {
return
parts
;
}
private
static
rea
d
Element
Array
(
htmlText
:
string
):
(
HTMLParagraphElement
|
HTMLHeadingElement
)[]
{
private
static
c
rea
te
Element
List
(
htmlText
:
string
):
(
HTMLParagraphElement
|
HTMLHeadingElement
)[]
{
const
el
=
document
.
createElement
(
'
html
'
);
el
.
innerHTML
=
htmlText
;
return
Array
.
from
(
el
.
children
[
1
].
children
)
as
(
HTMLParagraphElement
|
HTMLHeadingElement
)[];
...
...
@@ -34,7 +30,7 @@ export abstract class ClozeParser {
element
:
HTMLParagraphElement
|
HTMLHeadingElement
,
partIndex
:
number
,
parts
:
ClozePart
[][],
idService
:
IdService
):
ClozePart
[][]
{
parts
[
partIndex
]
=
[];
let
[
nextSpecialElementIndex
,
nextElementType
]
=
ClozeParser
.
getNext
Special
Element
(
element
.
innerHTML
);
let
[
nextSpecialElementIndex
,
nextElementType
]
=
ClozeParser
.
getNextElement
Marker
(
element
.
innerHTML
);
let
indexOffset
=
0
;
while
(
nextSpecialElementIndex
!==
-
1
)
{
...
...
@@ -50,7 +46,7 @@ export abstract class ClozeParser {
indexOffset
=
nextSpecialElementIndex
+
2
;
// + 2 to get rid of the marker, i.e. '\b'
[
nextSpecialElementIndex
,
nextElementType
]
=
ClozeParser
.
getNext
Special
Element
(
element
.
innerHTML
.
substring
(
indexOffset
));
ClozeParser
.
getNextElement
Marker
(
element
.
innerHTML
.
substring
(
indexOffset
));
}
parts
[
partIndex
].
push
({
type
:
element
.
localName
,
...
...
@@ -60,7 +56,7 @@ export abstract class ClozeParser {
return
parts
;
}
private
static
getNext
Special
Element
(
p
:
string
):
[
number
,
string
]
{
private
static
getNextElement
Marker
(
p
:
string
):
[
number
,
string
]
{
const
x
=
[];
if
(
p
.
indexOf
(
'
\\
d
'
)
>
0
)
{
x
.
push
(
p
.
indexOf
(
'
\\
d
'
));
...
...
@@ -106,7 +102,7 @@ export abstract class ClozeParser {
break
;
case
'
drop-list
'
:
newElement
=
new
DropListSimpleElement
(
elementModel
);
newElement
.
height
=
25
;
newElement
.
height
=
25
;
// TODO weg?
newElement
.
width
=
100
;
break
;
case
'
toggle-button
'
:
...
...
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