This is an automated email from the ASF dual-hosted git repository.

ddekany pushed a commit to branch 2.3-gae
in repository https://gitbox.apache.org/repos/asf/freemarker.git


The following commit(s) were added to refs/heads/2.3-gae by this push:
     new 7aebdda3 Improved documentation for the 
MarkupOutputFormat.outputForeign PR (and minor test cleanup).
7aebdda3 is described below

commit 7aebdda3d9f7b1215b6f6f6afa366bb668e42285
Author: ddekany <ddek...@apache.org>
AuthorDate: Thu Jan 5 02:38:20 2023 +0100

    Improved documentation for the MarkupOutputFormat.outputForeign PR (and 
minor test cleanup).
---
 src/main/java/freemarker/core/MarkupOutputFormat.java |  8 ++++++--
 src/manual/en_US/book.xml                             | 13 +++++++++++++
 src/test/java/freemarker/core/OutputFormatTest.java   |  6 +++---
 3 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/src/main/java/freemarker/core/MarkupOutputFormat.java 
b/src/main/java/freemarker/core/MarkupOutputFormat.java
index e98961eb..3ac39981 100644
--- a/src/main/java/freemarker/core/MarkupOutputFormat.java
+++ b/src/main/java/freemarker/core/MarkupOutputFormat.java
@@ -82,8 +82,12 @@ public abstract class MarkupOutputFormat<MO extends 
TemplateMarkupOutputModel> e
     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 2ac26041..baef4747 100644
--- a/src/manual/en_US/book.xml
+++ b/src/manual/en_US/book.xml
@@ -30245,6 +30245,19 @@ TemplateModel x = env.getVariable("x");  // get 
variable x</programlisting>
               mode.</para>
             </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
diff --git a/src/test/java/freemarker/core/OutputFormatTest.java 
b/src/test/java/freemarker/core/OutputFormatTest.java
index 1856166c..3e3207dc 100644
--- a/src/test/java/freemarker/core/OutputFormatTest.java
+++ b/src/test/java/freemarker/core/OutputFormatTest.java
@@ -746,11 +746,11 @@ public class OutputFormatTest extends TemplateTest {
     
     @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

Reply via email to