Я пытаюсь преобразовать разметку Pandoc в разметку wiki Confluence, я использую markdown2confluence, чтобы выполнить большую часть работы.
Это работает довольно хорошо, за исключением случаев, когда я говорю о CSS и FreeMarker, которые используют { & } в коде, в то время как Confluence использует {{ & }} чтобы отметить начало / конец блока кода. Поэтому мне нужно сопоставить шаблон, заключенный в {{...}} .
Если бы я знал (больше) Ruby, я мог бы исправить это там, но я парень из Unix старой школы, поэтому я подумал о awk или sed.
Итак, я дошел до:
sed 's/{{\([^}}]*\)}}/{{"\1"}}/g' tmp.wkd
который занимает:
First we need a way to select a state (or group of states) CSS uses what
is called a selector to choose which elements to apply to, we have been
using one up until now without noticing, it is the {{*}} at the beginning
of our CSS. This is a special selector that means select everything. So
the rule that follows it (the bit between {{{}} and {{}}} apply to every
polygon on the map. But CSS allows us to insert a filter instead by
using {{[...]}} instead of {{*}}.
и производит:
First we need a way to select a state (or group of states) CSS uses what
is called a selector to choose which elements to apply to, we have been
using one up until now without noticing, it is the {{"*"}} at the beginning
of our CSS. This is a special selector that means select everything. So
the rule that follows it (the bit between {{"{"}} and {{""}}} apply to every
polygon on the map. But CSS allows us to insert a filter instead by
using {{"[...]"}} instead of {{"*"}}.
Но то, что мне нужно, это:
First we need a way to select a state (or group of states) CSS uses what
is called a selector to choose which elements to apply to, we have been
using one up until now without noticing, it is the {{*}} at the beginning
of our CSS. This is a special selector that means select everything. So
the rule that follows it (the bit between {{\{}} and {{\}}} apply to every
polygon on the map. But CSS allows us to insert a filter instead by
using {{[...]}} instead of {{*}}.
Также необходимо обработать {{${type.name}}} который должен стать {{$\{type.name\}}} .
Есть две проблемы
- Мне нужно заменить
{на\{вместо использования кавычек, поэтому мне нужно как-то изменить\1. - Гадкий вид
{{}}}(который должен прийти{{\}}}не получится, независимо от того, как я пытаюсь закончить сопоставление с образцом.
