-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
93 lines (71 loc) · 2.27 KB
/
index.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
const worker = require('../worker')
const plugin = (processing_stage, file_name, translated_strings_array) => {
if ((processing_stage === 'post') && (file_name === 'description.txt')) {
worker.prepend_line_prefixes(file_name, translated_strings_array)
replace_with_html_entities(translated_strings_array)
}
}
const replace_with_html_entities = (translated_strings_array, max_chars_per_line = 40) => {
let line, matches, new_lines, next_line
for (let i=0; i < translated_strings_array.length; i++) {
line = translated_strings_array[i]
matches = worker.get_line_prefix_matches(line)
if (matches && (matches.length >= 3)) {
const L0 = matches[0].length
if (L0) {
const R0 = line.substring(L0, line.length)
const L1 = matches[1] ? matches[1].length : 0
const L2 = matches[2] ? matches[2].length : 0
const words = R0.split(/([ ]+)/)
const initial_line_length = L1 + L2
new_lines = []
next_line = initialize_next_line(L1, matches[2])
let line_length = initial_line_length
let next_word
advance_to_next_word(words)
while (words.length) {
if ((line_length > initial_line_length) && ((line_length + words[0].length) > max_chars_per_line)) {
new_lines.push(next_line.trim())
next_line = initialize_next_line(L1 + L2, '')
line_length = initial_line_length
advance_to_next_word(words)
if (!words.length) {
next_line = ''
break
}
}
next_word = words.shift()
next_line += next_word
line_length += next_word.length
}
if (next_line)
new_lines.push(next_line.trim())
translated_strings_array[i] = new_lines.join("\n")
}
}
}
}
const initialize_next_line = (L1, M2) => {
let next_line = ''
if (L1) {
next_line += (' ').repeat(L1)
}
if (M2) {
switch(M2[0]) {
case '*':
next_line += '● '
break
case '-':
next_line += '○ '
break
default:
next_line += M2
}
}
return next_line
}
const advance_to_next_word = (words) => {
while(words.length && words[0].trim() === '')
words.shift()
}
module.exports = plugin