713 dropWhile(line => !line.startsWith("<!-- END BIBLIOGRAPHY")).reverse) |
714 dropWhile(line => !line.startsWith("<!-- END BIBLIOGRAPHY")).reverse) |
714 } |
715 } |
715 else html |
716 else html |
716 } |
717 } |
717 } |
718 } |
|
719 |
|
720 |
|
721 |
|
722 /** cite commands and antiquotations **/ |
|
723 |
|
724 def cite_antiquotation(name: String, body: String): String = |
|
725 """\<^""" + name + """>\<open>""" + body + """\<close>""" |
|
726 |
|
727 def cite_antiquotation(name: String, location: String, citations: List[String]): String = { |
|
728 val body = |
|
729 (if (location.isEmpty) "" else Symbol.cartouche(location) + " in ") + |
|
730 citations.map(quote).mkString(" and ") |
|
731 cite_antiquotation(name, body) |
|
732 } |
|
733 |
|
734 private val Cite_Command = """\\(cite|nocite|citet|citep)((?:\[[^\]]*\])?)\{([^}]*)\}""".r |
|
735 private val Cite_Antiq = """@\{cite\s*([^}]*)\}""".r |
|
736 private val Cite_Macro = """\[\s*cite_macro\s*=\s*"?(\w+)"?\]\s*""".r |
|
737 |
|
738 def update_cite(str: String): String = { |
|
739 val str1 = |
|
740 Cite_Command.replaceAllIn(str, { m => |
|
741 val name = m.group(1) |
|
742 val loc = m.group(2) |
|
743 val location = |
|
744 if (loc.startsWith("[") && loc.endsWith("]")) loc.substring(1, loc.length - 1) |
|
745 else loc |
|
746 val citations = Library.space_explode(',', m.group(3)).map(_.trim) |
|
747 Regex.quoteReplacement(cite_antiquotation(name, location, citations)) |
|
748 }) |
|
749 val str2 = |
|
750 Cite_Antiq.replaceAllIn(str1, { m => |
|
751 val body0 = m.group(1) |
|
752 val (name, body1) = |
|
753 Cite_Macro.findFirstMatchIn(body0) match { |
|
754 case None => ("cite", body0) |
|
755 case Some(m1) => (m1.group(1), Cite_Macro.replaceAllIn(body0, "")) |
|
756 } |
|
757 val body2 = body1.replace("""\<close>""", """\<close> in""") |
|
758 Regex.quoteReplacement(cite_antiquotation(name, body2)) |
|
759 }) |
|
760 str2 |
|
761 } |
718 } |
762 } |