-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
executable file
·57 lines (52 loc) · 1.42 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const annotatedJson = (fragment) => {
const [string, annotation] = fragment.split(/\||・/); // split on | or ・ characters
return {
string,
annotation,
};
};
const State = {
value: '',
handleInput(input) {
this.value = input;
},
get output() {
return this.value
.split(/{|}|「|」/)
.map(annotatedJson)
.map(({ string, annotation }) =>
annotation
? m('ruby', [m('span', string), m('rt', annotation)])
: string
);
},
get debug() {
return this.value.split(/{|}|「|」/).map(annotatedJson);
},
};
const stringify = (json) => JSON.stringify(json, null, ' ');
const Instructions = {
view: () => [
m('p', 'Leiðbeiningar'),
m(
'p',
'Umlyktu orði sem þú vilt útskýra með slaufusvigum { } eða japanskum gæsalöppum 「 」. Settu | eða ・ á milli orðs og útskýringar.'
),
m('p', 'Dæmi:', m('br'), '{私|watashi}', m('br'), '「私・わたし」'),
],
};
const App = {
oninit: () =>
(State.value =
'「私・わたし」のシャツは「赤・aka」です: Skyrtan {mín|meen} er rauð'),
view: () => m('section.note', [
m(Instructions),
m('textarea', {
value: State.value,
oninput: (event) => State.handleInput(event.target.value),
}),
m('p', State.output),
// m('pre', stringify(State.debug)), // debug: show data structure
]),
};
m.mount(document.body, App);