Improved documentation for the MarkupOutputFormat.outputForeign PR (and minor test cleanup).
diff --git a/src/main/java/freemarker/core/MarkupOutputFormat.java b/src/main/java/freemarker/core/MarkupOutputFormat.java
index e98961e..3ac3998 100644
--- a/src/main/java/freemarker/core/MarkupOutputFormat.java
+++ b/src/main/java/freemarker/core/MarkupOutputFormat.java
@@ -82,8 +82,12 @@
public abstract void output(String textToEsc, Writer out) throws IOException, TemplateModelException;
/**
- * Outputs a value from a foreign output format; only used if {@link #isOutputFormatMixingAllowed()} is true.
- * By default will just let the other output format handle the value, but can be overridden to support more nuanced conversions.
+ * Outputs a value from a foreign output format; only used if {@link #isOutputFormatMixingAllowed()} return
+ * {@code true}. The default implementation in {@link MarkupOutputFormat} will just let the other
+ * {@link OutputFormat} to output value, but it can be overridden to support more nuanced conversions, or to check if outputting without
+ * conversion should be allowed.
+ *
+ * @since 2.3.32
*/
public <MO2 extends TemplateMarkupOutputModel<MO2>> void outputForeign(MO2 mo, Writer out) throws IOException, TemplateModelException {
mo.getOutputFormat().output(mo, out);
diff --git a/src/manual/en_US/book.xml b/src/manual/en_US/book.xml
index 2ac2604..baef474 100644
--- a/src/manual/en_US/book.xml
+++ b/src/manual/en_US/book.xml
@@ -30246,6 +30246,19 @@
</listitem>
<listitem>
+ <para>Added
+ <literal>freemarker.core.MarkupOutputFormat.outputForeign(MO2
+ mo, Writer out)</literal> method, which for a
+ <literal>MarkupOutputFormat</literal> where
+ <literal>isOutputFormatMixingAllowed()</literal> returns
+ <literal>true</literal>, allows full control over how to print a
+ different markup into it. This can check what other markup is
+ allowed, and do conversion if necessary. (<link
+ xlink:href="https://github.com/apache/freemarker/pull/83">GitHub
+ PR 83</link>)</para>
+ </listitem>
+
+ <listitem>
<para>Improved <literal>StringUtil.jsStringEnc</literal> and
<literal>javaSctringEsc</literal> to support quoting. Also
<literal>jsStringEnc</literal> now have a mode that targets both
diff --git a/src/test/java/freemarker/core/OutputFormatTest.java b/src/test/java/freemarker/core/OutputFormatTest.java
index 1856166..3e3207d 100644
--- a/src/test/java/freemarker/core/OutputFormatTest.java
+++ b/src/test/java/freemarker/core/OutputFormatTest.java
@@ -746,11 +746,11 @@
@Test
public void testMixedContent() throws Exception {
- getConfiguration().setRegisteredCustomOutputFormats(Collections.singleton(DummyOutputFormat.INSTANCE));
+ getConfiguration().setOutputFormat(DummyOutputFormat.INSTANCE);
addToDataModel("m1", HTMLOutputFormat.INSTANCE.fromMarkup("x"));
addToDataModel("m2", XMLOutputFormat.INSTANCE.fromMarkup("y"));
- assertOutput("<#ftl outputFormat='dummy'>${m1}", "x");
- assertErrorContains("<#ftl outputFormat='dummy'>${m2}", "is incompatible with");
+ assertOutput("${m1}", "x");
+ assertErrorContains("${m2}", "is incompatible with");
}
@Test