【发布时间】:2017-02-23 04:49:02
【问题描述】:
我需要通过首先将所有条目解析为其部分来更新用 Writer 编写的双语词典,例如
- 主词(字体 1,粗体)
- 外文等效音译(字体 1,斜体)
- 外文等价物(字体 2,粗体)
- 词性(字体 1,斜体)
文档的每一行都是主要单词,后面是上面列出的部分,每个部分用空格或标点符号分隔。
我需要自动执行逐行遍历整个文件的过程,并在每个部分之间放置一个分隔符,忽略空格和标点符号,这样我就可以将它大量导入到 Calc 文件中。换句话说,“每个部分”是具有相同字体和字体样式的字符序列(忽略空格和标点符号)。
我尝试了标准的 Search&Replace 功能和 AltSearch 扩展,但都无法完成任务。主要问题是我无法编写这样的搜索查询:
查找: 具有相同字体和 font_style 的连续字符,忽略空格和标点符号
替换: 上面找到的术语 + “分隔符”
任何建议我可以如何为此编写脚本,或者现有工具是否可以解决问题?
谢谢!
所需效果的伪代码:
var delimiter = "|"
Go to beginning of document
While not end of document do:
var $currLine = get line from doc
var $currChar = get next character which is not space or punctuation;
var $font = currChar.font
var $font_style - currChar.font_style (e.g. bold, italic, normal)
While not end of line do:
$currChar = next character which is not space or punctuation;
if (currChar.font != $font || currChar.font_style != $font_style) { // font or style has changed
print $delimiter
$font = currChar.font
$font_style - currChar.font_style (e.g. bold, italic, normal)
}
end While
end While
【问题讨论】:
标签: parsing scripting tokenize libreoffice writer