10 object Update { |
10 object Update { |
11 val update_elements: Markup.Elements = |
11 val update_elements: Markup.Elements = |
12 Markup.Elements(Markup.UPDATE, Markup.LANGUAGE) |
12 Markup.Elements(Markup.UPDATE, Markup.LANGUAGE) |
13 |
13 |
14 def update_xml(options: Options, xml: XML.Body): XML.Body = { |
14 def update_xml(options: Options, xml: XML.Body): XML.Body = { |
15 val path_cartouches = options.bool("update_path_cartouches") |
15 val update_path_cartouches = options.bool("update_path_cartouches") |
16 val cite_commands = options.bool("update_cite_commands") |
16 val update_cite_commands = options.bool("update_cite_commands") |
17 |
17 |
18 def upd(lang: Markup.Language, ts: XML.Body): XML.Body = |
18 def upd(lang: Markup.Language, ts: XML.Body): XML.Body = |
19 ts flatMap { |
19 ts flatMap { |
20 case XML.Wrapped_Elem(markup, body1, body2) => |
20 case XML.Wrapped_Elem(markup, body1, body2) => |
21 val body = if (markup.name == Markup.UPDATE) body1 else body2 |
21 val body = if (markup.name == Markup.UPDATE) body1 else body2 |
22 upd(lang, body) |
22 upd(lang, body) |
23 case XML.Elem(Markup.Language(lang1), body) => |
23 case XML.Elem(Markup.Language(lang1), body) => |
24 if (lang1.is_path && path_cartouches) { |
24 if (update_path_cartouches && lang1.is_path) { |
25 Token.read_embedded(Keyword.Keywords.empty, XML.content(body)) match { |
25 Token.read_embedded(Keyword.Keywords.empty, XML.content(body)) match { |
26 case Some(tok) => List(XML.Text(Symbol.cartouche(tok.content))) |
26 case Some(tok) => List(XML.Text(Symbol.cartouche(tok.content))) |
27 case None => upd(lang1, body) |
27 case None => upd(lang1, body) |
28 } |
28 } |
29 } |
29 } |
30 else upd(lang1, body) |
30 else upd(lang1, body) |
31 case XML.Elem(_, body) => upd(lang, body) |
31 case XML.Elem(_, body) => upd(lang, body) |
32 case XML.Text(s) if (lang.is_document || lang.is_antiquotation) && cite_commands => |
32 case XML.Text(s) |
|
33 if update_cite_commands && (lang.is_document || lang.is_antiquotation) => |
33 List(XML.Text(Bibtex.update_cite(s))) |
34 List(XML.Text(Bibtex.update_cite(s))) |
34 case t => List(t) |
35 case t => List(t) |
35 } |
36 } |
36 upd(Markup.Language.outer, xml) |
37 upd(Markup.Language.outer, xml) |
37 } |
38 } |