This is an automated email from the ASF dual-hosted git repository. juanpablo pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/jspwiki.git
commit 0769ce95695bd2d25077cb544855d1594361d8aa Author: Juan Pablo Santos RodrÃguez <[email protected]> AuthorDate: Thu Jan 13 11:29:25 2022 +0100 JSPWIKI-802: add Markdown support for WYSIWYG editor --- .../syntax/markdown/MarkdownADecorator.java | 82 +++++ .../syntax/markdown/MarkdownBrDecorator.java | 47 +++ .../syntax/markdown/MarkdownCodeDecorator.java | 49 +++ .../syntax/markdown/MarkdownDdDecorator.java | 42 +++ .../syntax/markdown/MarkdownDlDecorator.java | 48 +++ .../syntax/markdown/MarkdownDtDecorator.java | 42 +++ .../syntax/markdown/MarkdownFormDecorator.java | 53 ++++ .../syntax/markdown/MarkdownH1Decorator.java | 42 +++ .../syntax/markdown/MarkdownH2Decorator.java | 42 +++ .../syntax/markdown/MarkdownH3Decorator.java | 42 +++ .../syntax/markdown/MarkdownH4Decorator.java | 42 +++ .../syntax/markdown/MarkdownHrDecorator.java | 42 +++ .../syntax/markdown/MarkdownImageDecorator.java | 60 ++++ .../syntax/markdown/MarkdownInputDecorator.java | 54 ++++ .../syntax/markdown/MarkdownLiDecorator.java | 48 +++ .../syntax/markdown/MarkdownOlDecorator.java | 43 +++ .../syntax/markdown/MarkdownPDecorator.java | 48 +++ .../markdown/MarkdownPlainTextBoldDecorator.java | 50 ++++ .../markdown/MarkdownPlainTextCssDecorator.java | 62 ++++ .../MarkdownPlainTextCssSpecialDecorator.java | 61 ++++ .../markdown/MarkdownPlainTextItalicDecorator.java | 50 ++++ .../MarkdownPlainTextMonospaceDecorator.java | 50 ++++ .../syntax/markdown/MarkdownSelectDecorator.java | 60 ++++ .../syntax/markdown/MarkdownStrikeDecorator.java | 48 +++ .../syntax/markdown/MarkdownSubDecorator.java | 48 +++ .../syntax/markdown/MarkdownSupDecorator.java | 48 +++ .../syntax/markdown/MarkdownSyntaxDecorator.java | 94 ++++++ .../syntax/markdown/MarkdownTdDecorator.java | 43 +++ .../syntax/markdown/MarkdownTextAreaDecorator.java | 54 ++++ .../syntax/markdown/MarkdownThDecorator.java | 43 +++ .../syntax/markdown/MarkdownTheadDecorator.java | 56 ++++ .../syntax/markdown/MarkdownUlDecorator.java | 43 +++ .../markdown/MarkdownUnderlineDecorator.java | 48 +++ .../wiki/htmltowiki/syntax/markdown/package.html | 39 +++ .../HtmlStringToMarkdownWikiTranslatorTest.java | 330 +++++++++++++++++++++ 35 files changed, 2053 insertions(+) diff --git a/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownADecorator.java b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownADecorator.java new file mode 100644 index 0000000..a749368 --- /dev/null +++ b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownADecorator.java @@ -0,0 +1,82 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +package org.apache.wiki.htmltowiki.syntax.markdown; + +import org.apache.wiki.htmltowiki.XHtmlElementToWikiTranslator; +import org.apache.wiki.htmltowiki.XHtmlToWikiConfig; +import org.apache.wiki.htmltowiki.syntax.ADecorator; +import org.apache.wiki.htmltowiki.syntax.MarkupHelper; +import org.jdom2.Element; +import org.jdom2.JDOMException; + +import java.io.PrintWriter; + + +/** + * Markdown syntax implementation of {@link ADecorator}. + */ +class MarkdownADecorator extends ADecorator { + + MarkdownADecorator( final PrintWriter out, final XHtmlToWikiConfig config, final XHtmlElementToWikiTranslator chain ) { + super( out, config, chain ); + } + + /** {@inheritDoc} */ + @Override + protected void linkMarkup( final Element e ) throws JDOMException { + out.print( "[" ); + chain.translate( e ); + out.print( "]()" ); + } + + /** {@inheritDoc} */ + @Override + protected void linkMarkup( final Element e, final String ref ) throws JDOMException { + out.print( "[" ); + chain.translate( e ); + out.print( "](" ); + MarkupHelper.printUnescaped( out, ref ); + out.print( ")" ); + } + + /** {@inheritDoc} */ + @Override + protected void linkMarkup( final Element e, final String ref, final String additionalAttrs ) throws JDOMException { + // If the ref has the same value as the text and also if there + // are attributes, then just print: [ref](ref){attributes}. + out.print( "[" ); + chain.translate( e ); + out.print( "](" ); + MarkupHelper.printUnescaped( out, ref ); + out.print( "){" ); + out.print( additionalAttrs ); + out.print( "}" ); + } + + /** {@inheritDoc} */ + @Override + protected void linkMarkup( final String text, final String ref ) { + if( ref.equals( text ) ) { + out.print( "[" + text + "]()" ); + } else { + out.print( "[" + text + "](" + ref + ")" ); + } + } + +} diff --git a/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownBrDecorator.java b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownBrDecorator.java new file mode 100644 index 0000000..9f25eb9 --- /dev/null +++ b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownBrDecorator.java @@ -0,0 +1,47 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +package org.apache.wiki.htmltowiki.syntax.markdown; + +import org.apache.commons.lang3.StringUtils; +import org.apache.wiki.htmltowiki.WhitespaceTrimWriter; +import org.apache.wiki.htmltowiki.XHtmlElementToWikiTranslator; +import org.apache.wiki.htmltowiki.syntax.BrDecorator; + +import java.io.PrintWriter; +import java.util.Stack; + + +/** + * Markdown syntax implementation of {@link BrDecorator}. + */ +class MarkdownBrDecorator extends BrDecorator { + + private static final String INDENTATION_UNIT = StringUtils.repeat( WhitespaceTrimWriter.NO_TRIMMED_SPACE, 2 ); + + MarkdownBrDecorator( final PrintWriter out, final Stack< String > preStack, final XHtmlElementToWikiTranslator chain ) { + super( out, preStack, chain ); + } + + /** {@inheritDoc} */ + @Override + protected String markupBr() { + return INDENTATION_UNIT + "\n"; + } + +} diff --git a/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownCodeDecorator.java b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownCodeDecorator.java new file mode 100644 index 0000000..8ba0c1f --- /dev/null +++ b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownCodeDecorator.java @@ -0,0 +1,49 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +package org.apache.wiki.htmltowiki.syntax.markdown; + +import org.apache.wiki.htmltowiki.XHtmlElementToWikiTranslator; +import org.apache.wiki.htmltowiki.syntax.CodeDecorator; + +import java.io.PrintWriter; +import java.util.Stack; + + +/** + * Markdown syntax implementation of {@link CodeDecorator}. + */ +class MarkdownCodeDecorator extends CodeDecorator { + + MarkdownCodeDecorator( final PrintWriter out, final Stack< String > preStack, final XHtmlElementToWikiTranslator chain ) { + super( out, preStack, chain ); + } + + /** {@inheritDoc} */ + @Override + protected String markupCodeOpen() { + return "`"; + } + + /** {@inheritDoc} */ + @Override + protected String markupCodeClose() { + return "`"; + } + +} diff --git a/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownDdDecorator.java b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownDdDecorator.java new file mode 100644 index 0000000..48a9909 --- /dev/null +++ b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownDdDecorator.java @@ -0,0 +1,42 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +package org.apache.wiki.htmltowiki.syntax.markdown; + +import org.apache.wiki.htmltowiki.XHtmlElementToWikiTranslator; +import org.apache.wiki.htmltowiki.syntax.DdDecorator; + +import java.io.PrintWriter; + + +/** + * Markdown syntax implementation of {@link DdDecorator}. + */ +class MarkdownDdDecorator extends DdDecorator { + + MarkdownDdDecorator( final PrintWriter out, final XHtmlElementToWikiTranslator chain ) { + super( out, chain ); + } + + /** {@inheritDoc} */ + @Override + protected String markupDd() { + return ": "; + } + +} diff --git a/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownDlDecorator.java b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownDlDecorator.java new file mode 100644 index 0000000..7f503a0 --- /dev/null +++ b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownDlDecorator.java @@ -0,0 +1,48 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +package org.apache.wiki.htmltowiki.syntax.markdown; + +import org.apache.wiki.htmltowiki.XHtmlElementToWikiTranslator; +import org.apache.wiki.htmltowiki.syntax.DlDecorator; + +import java.io.PrintWriter; + + +/** + * Markdown syntax implementation of {@link DlDecorator}. + */ +class MarkdownDlDecorator extends DlDecorator { + + MarkdownDlDecorator( final PrintWriter out, final XHtmlElementToWikiTranslator chain ) { + super( out, chain ); + } + + /** {@inheritDoc} */ + @Override + protected String markupDlOpen() { + return "\n"; + } + + /** {@inheritDoc} */ + @Override + protected String markupDlClose() { + return "\n"; + } + +} diff --git a/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownDtDecorator.java b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownDtDecorator.java new file mode 100644 index 0000000..82a914a --- /dev/null +++ b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownDtDecorator.java @@ -0,0 +1,42 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +package org.apache.wiki.htmltowiki.syntax.markdown; + +import org.apache.wiki.htmltowiki.XHtmlElementToWikiTranslator; +import org.apache.wiki.htmltowiki.syntax.DtDecorator; + +import java.io.PrintWriter; + + +/** + * Markdown syntax implementation of {@link DtDecorator}. + */ +class MarkdownDtDecorator extends DtDecorator { + + MarkdownDtDecorator( final PrintWriter out, final XHtmlElementToWikiTranslator chain ) { + super( out, chain ); + } + + /** {@inheritDoc} */ + @Override + protected String markupDt() { + return ""; + } + +} diff --git a/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownFormDecorator.java b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownFormDecorator.java new file mode 100644 index 0000000..b356115 --- /dev/null +++ b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownFormDecorator.java @@ -0,0 +1,53 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +package org.apache.wiki.htmltowiki.syntax.markdown; + +import org.apache.wiki.htmltowiki.XHtmlElementToWikiTranslator; +import org.apache.wiki.htmltowiki.syntax.FormDecorator; + +import java.io.PrintWriter; + + +/** + * Markdown syntax implementation of {@link FormDecorator}. + */ +class MarkdownFormDecorator extends FormDecorator { + + MarkdownFormDecorator( final PrintWriter out, final XHtmlElementToWikiTranslator chain ) { + super( out, chain ); + } + + /** {@inheritDoc} */ + @Override + protected String markupFormOpen( final String name ) { + String form = "[{FormOpen"; + if( name != null ) { + form += " form='" + name + "'"; + } + form += "}]()"; + return form; + } + + /** {@inheritDoc} */ + @Override + protected String markupFormClose() { + return "[{FormClose}]()"; + } + +} diff --git a/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownH1Decorator.java b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownH1Decorator.java new file mode 100644 index 0000000..9c658ca --- /dev/null +++ b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownH1Decorator.java @@ -0,0 +1,42 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +package org.apache.wiki.htmltowiki.syntax.markdown; + +import org.apache.wiki.htmltowiki.XHtmlElementToWikiTranslator; +import org.apache.wiki.htmltowiki.syntax.H1Decorator; + +import java.io.PrintWriter; + + +/** + * Markdown syntax implementation of {@link H1Decorator}. + */ +class MarkdownH1Decorator extends H1Decorator { + + MarkdownH1Decorator( final PrintWriter out, final XHtmlElementToWikiTranslator chain ) { + super( out, chain ); + } + + /** {@inheritDoc} */ + @Override + protected String markupH1() { + return "# "; + } + +} diff --git a/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownH2Decorator.java b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownH2Decorator.java new file mode 100644 index 0000000..74a91b2 --- /dev/null +++ b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownH2Decorator.java @@ -0,0 +1,42 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +package org.apache.wiki.htmltowiki.syntax.markdown; + +import org.apache.wiki.htmltowiki.XHtmlElementToWikiTranslator; +import org.apache.wiki.htmltowiki.syntax.H2Decorator; + +import java.io.PrintWriter; + + +/** + * Markdown syntax implementation of {@link H2Decorator}. + */ +class MarkdownH2Decorator extends H2Decorator { + + MarkdownH2Decorator( final PrintWriter out, final XHtmlElementToWikiTranslator chain ) { + super( out, chain ); + } + + /** {@inheritDoc} */ + @Override + protected String markupH2() { + return "## "; + } + +} diff --git a/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownH3Decorator.java b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownH3Decorator.java new file mode 100644 index 0000000..5ba213b --- /dev/null +++ b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownH3Decorator.java @@ -0,0 +1,42 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +package org.apache.wiki.htmltowiki.syntax.markdown; + +import org.apache.wiki.htmltowiki.XHtmlElementToWikiTranslator; +import org.apache.wiki.htmltowiki.syntax.H3Decorator; + +import java.io.PrintWriter; + + +/** + * Markdown syntax implementation of {@link H3Decorator}. + */ +class MarkdownH3Decorator extends H3Decorator { + + MarkdownH3Decorator( final PrintWriter out, final XHtmlElementToWikiTranslator chain ) { + super( out, chain ); + } + + /** {@inheritDoc} */ + @Override + protected String markupH3() { + return "### "; + } + +} diff --git a/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownH4Decorator.java b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownH4Decorator.java new file mode 100644 index 0000000..0840987 --- /dev/null +++ b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownH4Decorator.java @@ -0,0 +1,42 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +package org.apache.wiki.htmltowiki.syntax.markdown; + +import org.apache.wiki.htmltowiki.XHtmlElementToWikiTranslator; +import org.apache.wiki.htmltowiki.syntax.H4Decorator; + +import java.io.PrintWriter; + + +/** + * Markdown syntax implementation of {@link H4Decorator}. + */ +class MarkdownH4Decorator extends H4Decorator { + + MarkdownH4Decorator( final PrintWriter out, final XHtmlElementToWikiTranslator chain ) { + super( out, chain ); + } + + /** {@inheritDoc} */ + @Override + protected String markupH4() { + return "#### "; + } + +} diff --git a/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownHrDecorator.java b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownHrDecorator.java new file mode 100644 index 0000000..5b8ea81 --- /dev/null +++ b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownHrDecorator.java @@ -0,0 +1,42 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +package org.apache.wiki.htmltowiki.syntax.markdown; + +import org.apache.wiki.htmltowiki.XHtmlElementToWikiTranslator; +import org.apache.wiki.htmltowiki.syntax.HrDecorator; + +import java.io.PrintWriter; + + +/** + * Markdown syntax implementation of {@link HrDecorator}. + */ +class MarkdownHrDecorator extends HrDecorator { + + MarkdownHrDecorator( final PrintWriter out, final XHtmlElementToWikiTranslator chain ) { + super( out, chain ); + } + + /** {@inheritDoc} */ + @Override + protected String markupHr() { + return "* * *"; + } + +} diff --git a/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownImageDecorator.java b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownImageDecorator.java new file mode 100644 index 0000000..1ad6929 --- /dev/null +++ b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownImageDecorator.java @@ -0,0 +1,60 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +package org.apache.wiki.htmltowiki.syntax.markdown; + +import org.apache.wiki.htmltowiki.XHtmlToWikiConfig; +import org.apache.wiki.htmltowiki.syntax.ImageDecorator; + +import java.io.PrintWriter; +import java.util.Map; + +/** + * Markdown syntax implementation of {@link ImageDecorator}. + */ +class MarkdownImageDecorator extends ImageDecorator { + + MarkdownImageDecorator( final PrintWriter out, final XHtmlToWikiConfig config ) { + super( out, config ); + } + + /** {@inheritDoc} */ + @Override + protected String markupImageSimpleOpen() { + return "["; + } + + /** {@inheritDoc} */ + @Override + protected String markupImageSimpleClose() { + return "]()"; + } + + /** {@inheritDoc} */ + @Override + protected void markupImageWithAttributes( final String src, final Map< String, Object > imageAttrs ) { + out.print( "[{Image src='" + src + "'" ); + for( final Map.Entry< String, Object > objectObjectEntry : imageAttrs.entrySet() ) { + if ( !objectObjectEntry.getValue().equals( "" ) ) { + out.print( " " + objectObjectEntry.getKey() + "='" + objectObjectEntry.getValue() + "'" ); + } + } + out.print( "}]()" ); + } + +} diff --git a/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownInputDecorator.java b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownInputDecorator.java new file mode 100644 index 0000000..50e121e --- /dev/null +++ b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownInputDecorator.java @@ -0,0 +1,54 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +package org.apache.wiki.htmltowiki.syntax.markdown; + +import org.apache.wiki.htmltowiki.XHtmlElementToWikiTranslator; +import org.apache.wiki.htmltowiki.syntax.InputDecorator; + +import java.io.PrintWriter; + + +/** + * Markdown syntax implementation of {@link InputDecorator}. + */ +class MarkdownInputDecorator extends InputDecorator { + + MarkdownInputDecorator( final PrintWriter out, final XHtmlElementToWikiTranslator chain ) { + super( out, chain ); + } + + /** {@inheritDoc} */ + @Override + protected String markupForInputAttribute( final String attr, final String value ) { + return " " + attr + "='" + value + "'"; + } + + /** {@inheritDoc} */ + @Override + protected String markupInputOpen() { + return "[{FormInput"; + } + + /** {@inheritDoc} */ + @Override + protected String markupInputClose() { + return "}]()"; + } + +} diff --git a/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownLiDecorator.java b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownLiDecorator.java new file mode 100644 index 0000000..37b600c --- /dev/null +++ b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownLiDecorator.java @@ -0,0 +1,48 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +package org.apache.wiki.htmltowiki.syntax.markdown; + +import org.apache.commons.lang3.StringUtils; +import org.apache.wiki.htmltowiki.WhitespaceTrimWriter; +import org.apache.wiki.htmltowiki.XHtmlElementToWikiTranslator; +import org.apache.wiki.htmltowiki.syntax.LiDecorator; + +import java.io.PrintWriter; +import java.util.Stack; + + +/** + * Markdown syntax implementation of {@link LiDecorator}. + */ +class MarkdownLiDecorator extends LiDecorator { + + private static final String INDENTATION_UNIT = StringUtils.repeat( WhitespaceTrimWriter.NO_TRIMMED_SPACE, 4 ); + + MarkdownLiDecorator( final PrintWriter out, final Stack< String > liStack, final XHtmlElementToWikiTranslator chain ) { + super( out, liStack, chain ); + } + + /** {@inheritDoc} */ + @Override + protected String markupLi( final Stack< String > liStack ) { + final String liIndentation = StringUtils.repeat( INDENTATION_UNIT, liStack.size() - 1 ); + return liIndentation + liStack.peek() + " "; + } + +} diff --git a/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownOlDecorator.java b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownOlDecorator.java new file mode 100644 index 0000000..0ebecdf --- /dev/null +++ b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownOlDecorator.java @@ -0,0 +1,43 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +package org.apache.wiki.htmltowiki.syntax.markdown; + +import org.apache.wiki.htmltowiki.XHtmlElementToWikiTranslator; +import org.apache.wiki.htmltowiki.syntax.OlDecorator; + +import java.io.PrintWriter; +import java.util.Stack; + + +/** + * Markdown syntax implementation of {@link OlDecorator}. + */ +class MarkdownOlDecorator extends OlDecorator { + + MarkdownOlDecorator( final PrintWriter out, final Stack< String > liStack, final XHtmlElementToWikiTranslator chain ) { + super( out, liStack, chain ); + } + + /** {@inheritDoc} */ + @Override + protected String markupOl() { + return "1."; + } + +} diff --git a/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownPDecorator.java b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownPDecorator.java new file mode 100644 index 0000000..a2747ec --- /dev/null +++ b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownPDecorator.java @@ -0,0 +1,48 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +package org.apache.wiki.htmltowiki.syntax.markdown; + +import org.apache.wiki.htmltowiki.XHtmlElementToWikiTranslator; +import org.apache.wiki.htmltowiki.syntax.PDecorator; + +import java.io.PrintWriter; + + +/** + * Markdown syntax implementation of {@link PDecorator}. + */ +class MarkdownPDecorator extends PDecorator { + + MarkdownPDecorator( final PrintWriter out, final XHtmlElementToWikiTranslator chain ) { + super( out, chain ); + } + + /** {@inheritDoc} */ + @Override + protected String markupPOpen() { + return System.lineSeparator(); + } + + /** {@inheritDoc} */ + @Override + protected String markupPClose() { + return System.lineSeparator(); + } + +} diff --git a/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownPlainTextBoldDecorator.java b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownPlainTextBoldDecorator.java new file mode 100644 index 0000000..ef42958 --- /dev/null +++ b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownPlainTextBoldDecorator.java @@ -0,0 +1,50 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +package org.apache.wiki.htmltowiki.syntax.markdown; + +import org.apache.wiki.htmltowiki.XHtmlElementToWikiTranslator; +import org.apache.wiki.htmltowiki.syntax.PlainTextBoldDecorator; +import org.apache.wiki.htmltowiki.syntax.PlainTextItalicDecorator; + +import java.io.PrintWriter; +import java.util.Stack; + + +/** + * Markdown syntax implementation of {@link PlainTextBoldDecorator}. + */ +class MarkdownPlainTextBoldDecorator extends PlainTextBoldDecorator { + + MarkdownPlainTextBoldDecorator( final PlainTextItalicDecorator ptid, final PrintWriter out, final Stack< String > preStack, final XHtmlElementToWikiTranslator chain ) { + super( ptid, out, preStack, chain ); + } + + /** {@inheritDoc} */ + @Override + protected String markupBoldOpen() { + return "**"; + } + + /** {@inheritDoc} */ + @Override + protected String markupBoldClose() { + return "**"; + } + +} diff --git a/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownPlainTextCssDecorator.java b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownPlainTextCssDecorator.java new file mode 100644 index 0000000..0cbc675 --- /dev/null +++ b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownPlainTextCssDecorator.java @@ -0,0 +1,62 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +package org.apache.wiki.htmltowiki.syntax.markdown; + +import org.apache.wiki.htmltowiki.XHtmlElementToWikiTranslator; +import org.apache.wiki.htmltowiki.syntax.PlainTextBoldDecorator; +import org.apache.wiki.htmltowiki.syntax.PlainTextCssDecorator; + +import java.io.PrintWriter; +import java.util.Stack; + + +/** + * Markdown syntax implementation of {@link PlainTextCssDecorator}. + */ +class MarkdownPlainTextCssDecorator extends PlainTextCssDecorator { + + MarkdownPlainTextCssDecorator( final PlainTextBoldDecorator ptbd, final PrintWriter out, final Stack< String > preStack, final XHtmlElementToWikiTranslator chain ) { + super( ptbd, out, preStack, chain ); + } + + /** {@inheritDoc} */ + @Override + protected String markupCssDivOpen( final String cssClass ) { + return "\n"; + } + + /** {@inheritDoc} */ + @Override + protected String markupCssDivClose( final String cssClass ) { + return " {." + cssClass + "}\n"; + } + + /** {@inheritDoc} */ + @Override + protected String markupCssSpanOpen( final String cssClass ) { + return ""; + } + + /** {@inheritDoc} */ + @Override + protected String markupCssSpanClose( final String cssClass ) { + return " {." + cssClass + "}"; + } + +} diff --git a/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownPlainTextCssSpecialDecorator.java b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownPlainTextCssSpecialDecorator.java new file mode 100644 index 0000000..2d7965d --- /dev/null +++ b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownPlainTextCssSpecialDecorator.java @@ -0,0 +1,61 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +package org.apache.wiki.htmltowiki.syntax.markdown; + +import org.apache.wiki.htmltowiki.XHtmlElementToWikiTranslator; +import org.apache.wiki.htmltowiki.syntax.PlainTextCssSpecialDecorator; + +import java.io.PrintWriter; +import java.util.Stack; + + +/** + * Markdown syntax implementation of {@link PlainTextCssSpecialDecorator}. + */ +class MarkdownPlainTextCssSpecialDecorator extends PlainTextCssSpecialDecorator { + + MarkdownPlainTextCssSpecialDecorator( final PrintWriter out, final Stack< String > preStack, final XHtmlElementToWikiTranslator chain ) { + super( out, preStack, chain ); + } + + /** {@inheritDoc} */ + @Override + protected String markupCssSpecialDivOpen( final String cssStyle ) { + return "\n"; + } + + /** {@inheritDoc} */ + @Override + protected String markupCssSpecialDivClose( final String cssStyle ) { + return " { style='" + cssStyle + "' }\n"; + } + + /** {@inheritDoc} */ + @Override + protected String markupCssSpecialOpen( final String cssStyle ) { + return ""; + } + + /** {@inheritDoc} */ + @Override + protected String markupCssSpecialClose( final String cssStyle ) { + return " { style='" + cssStyle + "' }"; + } + +} diff --git a/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownPlainTextItalicDecorator.java b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownPlainTextItalicDecorator.java new file mode 100644 index 0000000..397c41f --- /dev/null +++ b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownPlainTextItalicDecorator.java @@ -0,0 +1,50 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +package org.apache.wiki.htmltowiki.syntax.markdown; + +import org.apache.wiki.htmltowiki.XHtmlElementToWikiTranslator; +import org.apache.wiki.htmltowiki.syntax.PlainTextItalicDecorator; +import org.apache.wiki.htmltowiki.syntax.PlainTextMonospaceDecorator; + +import java.io.PrintWriter; +import java.util.Stack; + + +/** + * Markdown syntax implementation of {@link PlainTextItalicDecorator}. + */ +class MarkdownPlainTextItalicDecorator extends PlainTextItalicDecorator { + + MarkdownPlainTextItalicDecorator( final PlainTextMonospaceDecorator ptmd, final PrintWriter out, final Stack< String > preStack, final XHtmlElementToWikiTranslator chain ) { + super( ptmd, out, preStack, chain ); + } + + /** {@inheritDoc} */ + @Override + protected String markupItalicOpen() { + return "_"; + } + + /** {@inheritDoc} */ + @Override + protected String markupItalicClose() { + return "_"; + } + +} diff --git a/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownPlainTextMonospaceDecorator.java b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownPlainTextMonospaceDecorator.java new file mode 100644 index 0000000..4f513b0 --- /dev/null +++ b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownPlainTextMonospaceDecorator.java @@ -0,0 +1,50 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +package org.apache.wiki.htmltowiki.syntax.markdown; + +import org.apache.wiki.htmltowiki.XHtmlElementToWikiTranslator; +import org.apache.wiki.htmltowiki.syntax.PlainTextCssSpecialDecorator; +import org.apache.wiki.htmltowiki.syntax.PlainTextMonospaceDecorator; + +import java.io.PrintWriter; +import java.util.Stack; + + +/** + * Markdown syntax implementation of {@link PlainTextMonospaceDecorator}. + */ +class MarkdownPlainTextMonospaceDecorator extends PlainTextMonospaceDecorator { + + MarkdownPlainTextMonospaceDecorator( final PlainTextCssSpecialDecorator ptcsd, final PrintWriter out, final Stack< String > preStack, final XHtmlElementToWikiTranslator chain ) { + super( ptcsd, out, preStack, chain ); + } + + /** {@inheritDoc} */ + @Override + protected String markupMonospaceOpen() { + return "``"; + } + + /** {@inheritDoc} */ + @Override + protected String markupMonospaceClose() { + return "``"; + } + +} diff --git a/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownSelectDecorator.java b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownSelectDecorator.java new file mode 100644 index 0000000..b0e7350 --- /dev/null +++ b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownSelectDecorator.java @@ -0,0 +1,60 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +package org.apache.wiki.htmltowiki.syntax.markdown; + +import org.apache.wiki.htmltowiki.XHtmlElementToWikiTranslator; +import org.apache.wiki.htmltowiki.syntax.SelectDecorator; + +import java.io.PrintWriter; + + +/** + * Markdown syntax implementation of {@link SelectDecorator}. + */ +class MarkdownSelectDecorator extends SelectDecorator { + + MarkdownSelectDecorator( final PrintWriter out, final XHtmlElementToWikiTranslator chain ) { + super( out, chain ); + } + + /** {@inheritDoc} */ + @Override + protected String markupForSelectAttributeOpen( final String attr ) { + return " " + attr + "='"; + } + + /** {@inheritDoc} */ + @Override + protected String markupForSelectAttributeClose() { + return "'"; + } + + /** {@inheritDoc} */ + @Override + protected String markupSelectOpen() { + return "[{FormSelect"; + } + + /** {@inheritDoc} */ + @Override + protected String markupSelectClose() { + return "}]()"; + } + +} diff --git a/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownStrikeDecorator.java b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownStrikeDecorator.java new file mode 100644 index 0000000..44ace1b --- /dev/null +++ b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownStrikeDecorator.java @@ -0,0 +1,48 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +package org.apache.wiki.htmltowiki.syntax.markdown; + +import org.apache.wiki.htmltowiki.XHtmlElementToWikiTranslator; +import org.apache.wiki.htmltowiki.syntax.StrikeDecorator; + +import java.io.PrintWriter; + + +/** + * Markdown syntax implementation of {@link StrikeDecorator}. + */ +class MarkdownStrikeDecorator extends StrikeDecorator { + + MarkdownStrikeDecorator( final PrintWriter out, final XHtmlElementToWikiTranslator chain ) { + super( out, chain ); + } + + /** {@inheritDoc} */ + @Override + protected String markupStrikeOpen() { + return "<!---->"; + } + + /** {@inheritDoc} */ + @Override + protected String markupStrikeClose() { + return "{.strike}"; + } + +} diff --git a/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownSubDecorator.java b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownSubDecorator.java new file mode 100644 index 0000000..f53b338 --- /dev/null +++ b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownSubDecorator.java @@ -0,0 +1,48 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +package org.apache.wiki.htmltowiki.syntax.markdown; + +import org.apache.wiki.htmltowiki.XHtmlElementToWikiTranslator; +import org.apache.wiki.htmltowiki.syntax.SubDecorator; + +import java.io.PrintWriter; + + +/** + * Markdown syntax implementation of {@link SubDecorator}. + */ +class MarkdownSubDecorator extends SubDecorator { + + MarkdownSubDecorator( final PrintWriter out, final XHtmlElementToWikiTranslator chain ) { + super( out, chain ); + } + + /** {@inheritDoc} */ + @Override + protected String markupSubOpen() { + return "<!---->"; + } + + /** {@inheritDoc} */ + @Override + protected String markupSubClose() { + return "{.sub}"; + } + +} diff --git a/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownSupDecorator.java b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownSupDecorator.java new file mode 100644 index 0000000..23f7e97 --- /dev/null +++ b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownSupDecorator.java @@ -0,0 +1,48 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +package org.apache.wiki.htmltowiki.syntax.markdown; + +import org.apache.wiki.htmltowiki.XHtmlElementToWikiTranslator; +import org.apache.wiki.htmltowiki.syntax.SupDecorator; + +import java.io.PrintWriter; + + +/** + * Markdown syntax implementation of {@link SupDecorator}. + */ +class MarkdownSupDecorator extends SupDecorator { + + MarkdownSupDecorator( final PrintWriter out, final XHtmlElementToWikiTranslator chain ) { + super( out, chain ); + } + + /** {@inheritDoc} */ + @Override + protected String markupSupOpen() { + return "<!---->"; + } + + /** {@inheritDoc} */ + @Override + protected String markupSupClose() { + return "{.sup}"; + } + +} diff --git a/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownSyntaxDecorator.java b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownSyntaxDecorator.java new file mode 100644 index 0000000..1f3f99a --- /dev/null +++ b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownSyntaxDecorator.java @@ -0,0 +1,94 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +*/ +package org.apache.wiki.htmltowiki.syntax.markdown; + +import org.apache.wiki.htmltowiki.WhitespaceTrimWriter; +import org.apache.wiki.htmltowiki.XHtmlElementToWikiTranslator; +import org.apache.wiki.htmltowiki.XHtmlToWikiConfig; +import org.apache.wiki.htmltowiki.syntax.OptionDecorator; +import org.apache.wiki.htmltowiki.syntax.PlainTextDecorator; +import org.apache.wiki.htmltowiki.syntax.TableDecorator; +import org.apache.wiki.htmltowiki.syntax.TbodyDecorator; +import org.apache.wiki.htmltowiki.syntax.TextElementDecorator; +import org.apache.wiki.htmltowiki.syntax.TrDecorator; +import org.apache.wiki.htmltowiki.syntax.WikiSyntaxDecorator; + +import java.io.PrintWriter; +import java.util.Stack; + + +/** + * Markdown wiki syntax decorator which translates to wiki syntax. Delegates each kind of XHTML element to its specific decorator. + */ +public class MarkdownSyntaxDecorator extends WikiSyntaxDecorator { + + /** {@inheritDoc} */ + @Override + public void init( final PrintWriter out, + final Stack< String > liStack, + final Stack< String > preStack, + final WhitespaceTrimWriter outTrimmer, + final XHtmlToWikiConfig config, + final XHtmlElementToWikiTranslator chain ) { + this.config = config; + this.outTrimmer = outTrimmer; + this.chain = chain; + + this.cssStyle = new MarkdownPlainTextCssSpecialDecorator( out, preStack, chain ); + this.pre = new MarkdownPlainTextMonospaceDecorator( cssStyle, out, preStack, chain ); + this.em = new MarkdownPlainTextItalicDecorator( pre, out, preStack, chain ); + this.strong = new MarkdownPlainTextBoldDecorator( em, out, preStack, chain ); + this.css = new MarkdownPlainTextCssDecorator( strong, out, preStack, chain ); + this.plainText = new PlainTextDecorator( css, out, preStack, chain ); + + this.a = new MarkdownADecorator( out, config, chain ); + this.br = new MarkdownBrDecorator( out, preStack, chain ); + this.code = new MarkdownCodeDecorator( out, preStack, chain ); + this.dd = new MarkdownDdDecorator( out, chain ); + this.dl = new MarkdownDlDecorator( out, chain ); + this.dt = new MarkdownDtDecorator( out, chain ); + this.form = new MarkdownFormDecorator( out, chain ); + this.hr = new MarkdownHrDecorator( out, chain ); + this.h1 = new MarkdownH1Decorator( out, chain ); + this.h2 = new MarkdownH2Decorator( out, chain ); + this.h3 = new MarkdownH3Decorator( out, chain ); + this.h4 = new MarkdownH4Decorator( out, chain ); + this.img = new MarkdownImageDecorator( out, config ); + this.input = new MarkdownInputDecorator( out, chain ); + this.li = new MarkdownLiDecorator( out, liStack, chain ); + this.ol = new MarkdownOlDecorator( out, liStack, chain ); + this.option = new OptionDecorator( out, chain ); + this.p = new MarkdownPDecorator( out, chain ); + this.table = new TableDecorator( out, outTrimmer, chain ); + this.tbody = new TbodyDecorator( out, chain ); + this.td = new MarkdownTdDecorator( out, preStack, chain ); + this.th = new MarkdownThDecorator( out, preStack, chain ); + this.thead = new MarkdownTheadDecorator( out, chain ); + this.tr = new TrDecorator( out, chain ); + this.textarea = new MarkdownTextAreaDecorator( out, chain ); + this.textElement = new TextElementDecorator( out, preStack ); + this.select = new MarkdownSelectDecorator( out, chain ); + this.strike = new MarkdownStrikeDecorator( out, chain ); + this.sub = new MarkdownSubDecorator( out, chain ); + this.sup = new MarkdownSupDecorator( out, chain ); + this.ul = new MarkdownUlDecorator( out, liStack, chain ); + this.underline = new MarkdownUnderlineDecorator( out, chain ); + } + +} diff --git a/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownTdDecorator.java b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownTdDecorator.java new file mode 100644 index 0000000..fec1e3d --- /dev/null +++ b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownTdDecorator.java @@ -0,0 +1,43 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +package org.apache.wiki.htmltowiki.syntax.markdown; + +import org.apache.wiki.htmltowiki.XHtmlElementToWikiTranslator; +import org.apache.wiki.htmltowiki.syntax.TdDecorator; + +import java.io.PrintWriter; +import java.util.Stack; + + +/** + * Markdown syntax implementation of {@link TdDecorator}. + */ +class MarkdownTdDecorator extends TdDecorator { + + MarkdownTdDecorator( final PrintWriter out, final Stack< String > preStack, final XHtmlElementToWikiTranslator chain ) { + super( out, preStack, chain ); + } + + /** {@inheritDoc} */ + @Override + protected String markupTd() { + return "| "; + } + +} diff --git a/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownTextAreaDecorator.java b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownTextAreaDecorator.java new file mode 100644 index 0000000..32a22de --- /dev/null +++ b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownTextAreaDecorator.java @@ -0,0 +1,54 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +package org.apache.wiki.htmltowiki.syntax.markdown; + +import org.apache.wiki.htmltowiki.XHtmlElementToWikiTranslator; +import org.apache.wiki.htmltowiki.syntax.TextAreaDecorator; + +import java.io.PrintWriter; + + +/** + * Markdown syntax implementation of {@link TextAreaDecorator}. + */ +class MarkdownTextAreaDecorator extends TextAreaDecorator { + + MarkdownTextAreaDecorator( final PrintWriter out, final XHtmlElementToWikiTranslator chain ) { + super( out, chain ); + } + + /** {@inheritDoc} */ + @Override + protected String markupForTextAreaAttribute( final String attr, final String value ) { + return " " + attr + "='" + value + "'"; + } + + /** {@inheritDoc} */ + @Override + protected String markupTextAreaOpen() { + return "[{FormTextarea"; + } + + /** {@inheritDoc} */ + @Override + protected String markupTextAreaClose() { + return "}]()"; + } + +} diff --git a/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownThDecorator.java b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownThDecorator.java new file mode 100644 index 0000000..d1efeec --- /dev/null +++ b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownThDecorator.java @@ -0,0 +1,43 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +package org.apache.wiki.htmltowiki.syntax.markdown; + +import org.apache.wiki.htmltowiki.XHtmlElementToWikiTranslator; +import org.apache.wiki.htmltowiki.syntax.ThDecorator; + +import java.io.PrintWriter; +import java.util.Stack; + + +/** + * Markdown syntax implementation of {@link ThDecorator}. + */ +class MarkdownThDecorator extends ThDecorator { + + MarkdownThDecorator( final PrintWriter out, final Stack< String > preStack, final XHtmlElementToWikiTranslator chain ) { + super( out, preStack, chain ); + } + + /** {@inheritDoc} */ + @Override + protected String markupTh() { + return "| "; + } + +} diff --git a/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownTheadDecorator.java b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownTheadDecorator.java new file mode 100644 index 0000000..9a1c858 --- /dev/null +++ b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownTheadDecorator.java @@ -0,0 +1,56 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +package org.apache.wiki.htmltowiki.syntax.markdown; + +import org.apache.wiki.htmltowiki.XHtmlElementToWikiTranslator; +import org.apache.wiki.htmltowiki.syntax.TheadDecorator; +import org.jdom2.Content; +import org.jdom2.Element; +import org.jdom2.JDOMException; + +import java.io.PrintWriter; + + +/** + * Markdown syntax implementation of {@link TheadDecorator}. + */ +class MarkdownTheadDecorator extends TheadDecorator { + + MarkdownTheadDecorator( final PrintWriter out, final XHtmlElementToWikiTranslator chain ) { + super( out, chain ); + } + + /** {@inheritDoc} */ + @Override + public void decorate( final Element element ) throws JDOMException { + super.decorate( element ); + final Content cNestedTr = element.getContent().get( 0 ); + if( cNestedTr instanceof Element ) { + final Element nestedTr = ( Element )cNestedTr; + final int ths = nestedTr.getContent().size(); + if( ths > 0 ) { + for( int i = 0 ; i < ths; i++ ) { + out.print( "|---" ); + } + } + out.println(); + } + } + +} diff --git a/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownUlDecorator.java b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownUlDecorator.java new file mode 100644 index 0000000..60b865a --- /dev/null +++ b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownUlDecorator.java @@ -0,0 +1,43 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +package org.apache.wiki.htmltowiki.syntax.markdown; + +import org.apache.wiki.htmltowiki.XHtmlElementToWikiTranslator; +import org.apache.wiki.htmltowiki.syntax.UlDecorator; + +import java.io.PrintWriter; +import java.util.Stack; + + +/** + * Markdown syntax implementation of {@link UlDecorator}. + */ +class MarkdownUlDecorator extends UlDecorator { + + MarkdownUlDecorator( final PrintWriter out, final Stack< String > liStack, final XHtmlElementToWikiTranslator chain ) { + super( out, liStack, chain ); + } + + /** {@inheritDoc} */ + @Override + protected String markupUl() { + return "*"; + } + +} diff --git a/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownUnderlineDecorator.java b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownUnderlineDecorator.java new file mode 100644 index 0000000..00887c6 --- /dev/null +++ b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/MarkdownUnderlineDecorator.java @@ -0,0 +1,48 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +package org.apache.wiki.htmltowiki.syntax.markdown; + +import org.apache.wiki.htmltowiki.XHtmlElementToWikiTranslator; +import org.apache.wiki.htmltowiki.syntax.UnderlineDecorator; + +import java.io.PrintWriter; + + +/** + * Markdown syntax implementation of {@link UnderlineDecorator}. + */ +class MarkdownUnderlineDecorator extends UnderlineDecorator { + + MarkdownUnderlineDecorator( final PrintWriter out, final XHtmlElementToWikiTranslator chain ) { + super( out, chain ); + } + + /** {@inheritDoc} */ + @Override + protected String markupUnderlineOpen() { + return "<!---->"; + } + + /** {@inheritDoc} */ + @Override + protected String markupUnderlineClose() { + return "{style:'text-decoration:underline;'}"; + } + +} diff --git a/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/package.html b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/package.html new file mode 100644 index 0000000..52b39ad --- /dev/null +++ b/jspwiki-markdown/src/main/java/org/apache/wiki/htmltowiki/syntax/markdown/package.html @@ -0,0 +1,39 @@ +<!-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> + +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<html lang="en"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> +<title>APIDocs for org.apache.wiki.htmltowiki.syntax.markdown</title> +</head> +<body> +Markdown syntax decoration related classes. + +<h3>Package Specification</h3> + +The entry point for this class is MarkdownSyntaxDecorator, an implementation of SyntaxDecorator which outputs Markdown syntax +from valid XHTML elements. The rest of the package consists of package-private decorators which handle the translation of +specific XHTML elements into their corresponding JSPMarkdown syntax markup. + +<h3>Related Documentation</h3> +See org.apache.wiki.htmltowiki package specification. + +</body> +</html> \ No newline at end of file diff --git a/jspwiki-markdown/src/test/java/org/apache/wiki/htmltowiki/syntax/markdown/HtmlStringToMarkdownWikiTranslatorTest.java b/jspwiki-markdown/src/test/java/org/apache/wiki/htmltowiki/syntax/markdown/HtmlStringToMarkdownWikiTranslatorTest.java new file mode 100644 index 0000000..69d7fc0 --- /dev/null +++ b/jspwiki-markdown/src/test/java/org/apache/wiki/htmltowiki/syntax/markdown/HtmlStringToMarkdownWikiTranslatorTest.java @@ -0,0 +1,330 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + */ +package org.apache.wiki.htmltowiki.syntax.markdown; + +import org.apache.wiki.TestEngine; +import org.apache.wiki.api.core.Engine; +import org.apache.wiki.htmltowiki.HtmlStringToWikiTranslator; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + + +/** + * JUnit test cases for Converting Html to Markdown Wiki Markup. + */ +public class HtmlStringToMarkdownWikiTranslatorTest { + + static Engine e = TestEngine.build( TestEngine.with( "jspwiki.syntax.decorator", MarkdownSyntaxDecorator.class.getName() ) ); + HtmlStringToWikiTranslator html2wiki; + + @BeforeEach + public void setUp() { + html2wiki = new HtmlStringToWikiTranslator( e ); + } + + @Test + public void testAnchor() throws Exception { + Assertions.assertEquals( "[startup.bat]()", html2wiki.translate( + " <a class=\"attachment\" href=\"attach?page=startup.bat\">startup.bat</a><a href=\"PageInfo.jsp?page=startup.bat\"><img src=\"images/attachment_small.png\" alt=\"(att)\" border=\"0\"></a>" ) ); + + Assertions.assertEquals( "[http://www.startup.de]()", html2wiki.translate( + "<a class=\"external\" href=\"http://www.startup.de\">http://www.startup.de</a><img class=\"outlink\" src=\"images/out.png\" alt=\"\">" ) ); + + Assertions.assertEquals( " [AbsolutelyTestNotExisting]\n\n", + html2wiki.translate( + "<table class=\"imageplugin\" align=\"left\" border=\"0\">\r\n" + "<tbody><tr><td><br>\r\n" + "</td></tr>\r\n" + "</tbody></table>\r\n" + + "\r\n" + " [AbsolutelyTestNotExisting]<p>\r\n" + "<table class=\"imageplugin\" align=\"left\" border=\"0\">\r\n" + "\r\n" + + "<tbody>\r\n" + "</tbody></table>\r\n" + "\r\n" + "</p><p>\r\n" + "</p>" ) ); + + Assertions.assertEquals( "[ThisPageDoesNotExist]()", html2wiki.translate( "<a href=\"Edit.jsp?page=ThisPageDoesNotExist\">ThisPageDoesNotExist</a>" ) ); + + Assertions.assertEquals( "[/JSPWiki/wysiwyg/FCKeditor/editor/images/smiley/msn/sad_smile.gif]()", + html2wiki.translate( "<img src=\"/JSPWiki/wysiwyg/FCKeditor/editor/images/smiley/msn/sad_smile.gif\" alt=\"\"/>" ) ); + + Assertions.assertEquals( "[AugumentedWikiLinks](AugumentedWikiLinks){title='my \"custom\" title' target='_blank'}", html2wiki.translate( + "<a class=\"wikipage\" href=\"Wiki.jsp?page=AugumentedWikiLinks\" target=\"_blank\" title=\"my 'custom' title\">AugumentedWikiLinks</a>" ) ); + + // footnote links + Assertions.assertEquals( "[23]()", html2wiki.translate( "<a class=\"footnoteref\" href=\"#ref-PageName-23\">[23]</a>" ) ); + Assertions.assertEquals( "[something](23)", html2wiki.translate( "<a class=\"footnoteref\" href=\"#ref-PageName-23\">[something]</a>" ) ); + + } + + @Test + public void testTable() throws Exception { + Assertions.assertEquals( "a\n| erste\n", html2wiki.translate( "a <table border=\"1\"> <tbody><tr> <td> erste</td> </tr> </tbody> </table>" ) ); + + Assertions.assertEquals( + "| Throalisches Jahr | Ereignis\n|---|---\n" + "| 100 v. TH | Elianer Messias \u00fcbersetzt die tausendj\u00e4hrigen B\u00fccher von Harrow.\n" + + "| 50 v. TH | Gr\u00fcndung Nehr?eshams und der ewigen Bibliothek.\n", + html2wiki.translate( "<table class=\"wikitable\" border=\"1\"><thead><tr><th> Throalisches Jahr </th><th> Ereignis</th></tr></thead><tbody>\n" + + "<tr><td> 100 v. TH</td><td> Elianer Messias \u00fcbersetzt die tausendj\u00e4hrigen B\u00fccher von Harrow.</td></tr>\n" + + "<tr><td> 50 v. TH</td><td> Gr\u00fcndung Nehr?eshams und der ewigen Bibliothek.</td></tr>\n" + "</tbody></table>" ) ); + + Assertions.assertEquals( + "| Throalisches Jahr | Ereignis\n|---|---\n" + "| 100 v. TH | Elianer Messias \u00fcbersetzt die tausendj\u00e4hrigen B\u00fccher von Harrow.\n" + + "| 50 v. TH | Gr\u00fcndung Nehr?eshams und der ewigen Bibliothek.\n\u00A0", + html2wiki.translate( "<table class=\"wikitable\" border=\"1\"><thead><tr><th> Throalisches Jahr </th><th> Ereignis</th></tr></thead><tbody>\n" + + "<tr><td> 100 v. TH</td><td> Elianer Messias \u00fcbersetzt die tausendj\u00e4hrigen B\u00fccher von Harrow.</td></tr>\n" + + "<tr><td> 50 v. TH</td><td> Gr\u00fcndung Nehr?eshams und der ewigen Bibliothek.</td></tr>\n" + "</tbody></table> " ) ); + + Assertions.assertEquals( "| 3. Rang | Name des Helden, den der Bogen t\u00f6ten sollte.\n" + "| F\u00e4higkeit | Bonus auf die Initiative von 1\n", + html2wiki.translate( + "<table class=\"wikitable\" border=\"1\"><tbody><tr><td> 3. Rang</td><td> Name des Helden, den der Bogen t\u00f6ten sollte.</td></tr>\n" + + "<tr><td> F\u00e4higkeit</td><td> Bonus auf die Initiative von 1</td></tr></tbody></table></p><p>" ) ); + + Assertions.assertEquals( + "| Name: [Christian](ChristianS) \n\u00A0Geschicklichkeit: 2 \nHang zu perversen Sexorgien. Jongliert mit Worten und K\u00f6pfen. \n[Berian Nachtschleicher](Berian) \n[XLerul]() \n[Effifot Erif](EffifotErif)\n", + html2wiki.translate( + "<table class=\"wikitable\" border=\"1\"><tbody><tr><td> Name: <a class=\"wikipage\" href=\"Wiki.jsp?page=ChristianS\">Christian</a> <br> Geschicklichkeit: 2 <br> Hang zu perversen Sexorgien. Jongliert mit Worten und K\u00f6pfen. <br> <a class=\"wikipage\" href=\"Wiki.jsp?page=Berian\">Berian Nachtschleicher</a> <br> <a class=\"wikipage\" href=\"Wiki.jsp?page=XLerul\">XLerul</a> <br> <a class=\"wikipage\" href=\"Wiki.jsp?page=EffifotErif\">Effifot Erif</a></t [...] + + } + + @Test + public void testRulers() throws Exception { + Assertions.assertEquals( "a\n* * *\nb", html2wiki.translate( "a<hr/>b" ) ); + Assertions.assertEquals( "by\n" + "* * *\n" + "Dies", html2wiki.translate( "by\n" + "<hr>\n" + "Dies" ) ); + } + + @Test + public void testParagraphs() throws Exception { + Assertions.assertEquals( "a\nb\nc", html2wiki.translate( "a<p>b</p>c" ) ); + + Assertions.assertEquals( "ab", html2wiki.translate( "a<p></p>b" ) ); + + Assertions.assertEquals( "a\n\nb", html2wiki.translate( "a<p>\n</p>b" ) ); + + Assertions.assertEquals( "\n \n\n**Willkommen** \n\n \n\nUnd niemand wird sie sehen \n\nEine Page ...\n\nAls Unterthema\n", html2wiki.translate( + "<p><br />\n<strong>Willkommen</strong> <br />\n<br />\nUnd niemand wird sie sehen <br />\nEine Page ...</p>\n<p>Als Unterthema</p>" ) ); + + Assertions.assertEquals( "\n\u00A0\n\nTop\n\nBottom\n\n\n", html2wiki.translate( "<p> </p><p>Top</p>\n<p></p>\n<p></p>\n<p>Bottom</p> <p> </p>" ) ); + } + + @Test + public void testWhitespace() throws Exception { + Assertions.assertEquals( "", html2wiki.translate( "" ) ); + Assertions.assertEquals( "", html2wiki.translate( " " ) ); + Assertions.assertEquals( "", html2wiki.translate( "<div>\n\n\n</div>" ) ); + Assertions.assertEquals( "a ", html2wiki.translate( "a\n \n\n \t\r\n" ) ); + } + + @Test + public void testLists() throws Exception { + Assertions.assertEquals( "\n* Punkt 1\n* Punkt 2\n", html2wiki.translate( "<ul><li>Punkt 1</li><li>Punkt 2</li></ul>" ) ); + Assertions.assertEquals( "\n1. Punkt 1\n1. Punkt 2\n", html2wiki.translate( "<ol><li>Punkt 1</li><li>Punkt 2</li></ol>" ) ); + Assertions.assertEquals( "\n1. Punkt 1\n 1. Punkt 2\n\n", html2wiki.translate( "<ol><li>Punkt 1<ol><li>Punkt 2</li></ol></li></ol>" ) ); + Assertions.assertEquals( "\n* Punkt 1\n * Punkt 2\n\n", html2wiki.translate( "<ul><li>Punkt 1<ul><li>Punkt 2</li></ul></li></ul>" ) ); + Assertions.assertEquals( "\n* Punkt 1\n 1. Punkt 2\n\n", html2wiki.translate( "<ul><li>Punkt 1<ol><li>Punkt 2</li></ol></li></ul>" ) ); + Assertions.assertEquals( + "\n1. list item 1\n1. list item 2\n 1. list item 2.1\n * list item 2.1.1\n * list item 2.1.2\n 1. list item 2.2\n1. list item 3\n 1. list item 3.1\n * list item 3.1.1\n 1. list item 3.2\n1. list item 4\n", + html2wiki.translate( + "<ol> <li>list item 1</li> <li>list item 2 <ol> <li>list item 2.1 <ul> <li>list item 2.1.1</li> <li>list item 2.1.2</li> </ul> </li> <li>list item 2.2</li> </ol> </li> <li>list item 3 <ol> <li>list item 3.1 <ul> <li>list item 3.1.1</li> </ul> </li> <li>list item 3.2</li> </ol> </li> <li>list item 4</li> </ol>" ) ); + + Assertions.assertEquals( + "\n* Diese Karte kann von jedem editiert und um neue Links erweitert werden. \nKlickt einfach unten neben der Karte auf ``[edit]``\n", + html2wiki.translate( + "<ul><li> Diese Karte kann von jedem editiert und um neue Links erweitert werden.<br>Klickt einfach unten neben der Karte auf <span class=\"inline-code\">[edit]</span></li></ul>" ) ); + + Assertions.assertEquals( + "\n* Diese Karte kann von jedem editiert und um neue Links erweitert werden. \nKlickt einfach unten neben der Karte auf ``[edit]``\n", + html2wiki.translate( + "<ul><li> Diese Karte kann von jedem editiert und um neue Links erweitert werden.<br>Klickt einfach unten neben der Karte auf <span class=\"inline-code\">[edit]</span></li></ul>" ) ); + + } + + @Test + public void testPre() throws Exception { + Assertions.assertEquals( "\n``hallo``\n", html2wiki.translate( "<pre>hallo</pre>" ) ); + Assertions.assertEquals( "\n``Hallo\nWelt!\n\n``\n", html2wiki.translate( "<pre>Hallo<br>Welt!<br><br></pre>" ) ); + Assertions.assertEquals( "\n``\n\n\n\nHallo\n\n\n\nWelt!\n\n\n\n``\n", html2wiki.translate( "\n\n\n\n<pre>\n\n\n\nHallo\n\n\n\nWelt!\n\n\n\n</pre>\n\n\n\n" ) ); + + Assertions.assertEquals( "\n``\n\n* Baltramon \n lasdjfh\n\n``\n", html2wiki.translate( "<pre>\n\n* Baltramon \n lasdjfh\n\n</pre>" ) ); + + /* + * // The style "font-family: courier new" is no longer translated as monospace text, so this test case is no longer needed. Assertions.assertEquals( + * "Diese Karte{{{ kann }}} von", html2wiki .translate( "Diese Karte<span style=\"font-family: courier new,courier,mono;\"> kann </span> von" ) ); + */ + + Assertions.assertEquals( "Fahrt einfac``h mit\u00A0\u00A0 \n der \u00A0 Maus`` drueber", html2wiki + .translate( "Fahrt einfac<span class=\"inline-code\">h mit <br> der Maus</span> drueber" ) ); + + } + + @Test + public void testTT() throws Exception { + Assertions.assertEquals( "`hallo`", html2wiki.translate( "<tt>hallo</tt>" ) ); + Assertions.assertEquals( "`hallo`", html2wiki.translate( "<code>hallo</code>" ) ); + } + + @Test + public void testCenter() throws Exception { + Assertions.assertEquals( "\nHello \n\nWorld! { style=' text-align: center;' }\n", + html2wiki.translate( "<div style=\"text-align: center;\">Hello<br>World!</div>" ) ); + + Assertions.assertEquals( "**Hello \nWorld! { style=' text-align: center; display: block;' }**", + html2wiki.translate( "<span style=\"font-weight: bold; text-align: center; display: block;\">Hello<br>World!</span>" ) ); + + } + + @Test + public void testImage() throws Exception { + Assertions.assertEquals( "[{Image src='Homunkulus/homunculus4.jpg' align='left'}]()", html2wiki.translate( + "<table class=\"imageplugin\" align=\"left\" border=\"0\"> <tbody><tr><td><img src=\"attach?page=Homunkulus%2Fhomunculus4.jpg\"></td></tr> </tbody></table>" ) ); + + Assertions.assertEquals( "[{Image src='AbenteuerQuilpins/Quilpins.jpg' align='left'}]()", + html2wiki.translate( "<table class=\"imageplugin\" align=\"left\" border=\"0\">\r\n" + + "<tbody><tr><td><img src=\"attach?page=AbenteuerQuilpins%2FQuilpins.jpg\"></td></tr>\r\n</tbody>" + "</table>" ) ); + + Assertions.assertEquals( "[{Image src='AbenteuerQuilpins/Quilpins.jpg' caption='Testing Image' style='font-size: 120%; color: green;'}]()", + html2wiki.translate( "<table class=\"imageplugin\" style=\"font-size: 120%; color: green;\" border=\"0\">\r\n" + + "<caption align=\"bottom\">Testing Image</caption>\r\n" + + "<tbody><tr><td><img src=\"attach?page=AbenteuerQuilpins%2FQuilpins.jpg\"></td></tr>\r\n</tbody>" + "</table>" ) ); + + Assertions.assertEquals( + "[{Image src='http://opi.yahoo.com/online?u=YahooUser1234&m=g&t=2' link='http://edit.yahoo.com/config/send_webmesg?.target=YahooUser1234&.src=pg'}]()", + html2wiki.translate( "<table class=\"imageplugin\" border=\"0\">\r\n" + "<tbody><tr><td>" + + "<a href=\"http://edit.yahoo.com/config/send_webmesg?.target=YahooUser1234&.src=pg\">" + + "<img src=\"http://opi.yahoo.com/online?u=YahooUser1234&m=g&t=2\">" + "</a></td></tr>\r\n" + "</tbody>" + "</table>" ) ); + + Assertions.assertEquals( + "[{Image src='homunculus4.jpg' align='left' height='100px' width='100px' alt='alt text' caption='caption text' link='http://google.de' border='1'}]()", + html2wiki.translate( "<table class=\"imageplugin\" align=\"left\" border=\"0\"> \r\n" + + " <caption align=\"bottom\">caption text</caption> \r\n" + " <tbody><tr><td>\r\n" + + " <a href=\"http://google.de\"><img src=\"homunculus4.jpg\" alt=\"alt text\" border=\"1\" height=\"100px\" width=\"100px\">\r\n" + + " </a></td></tr> \r\n" + " </tbody> \r\n" + "</table>" ) ); + + Assertions.assertEquals( + "[{Image src='http://opi.yahoo.com/online?u=YahooUser1234&m=g&t=2' link='http://edit.yahoo.com/config/send_webmesg?.target=YahooUser1234&.src=pg'}]()", + html2wiki.translate( " <a href=\"http://edit.yahoo.com/config/send_webmesg?.target=YahooUser1234&.src=pg\">\r\n" + + " <img src=\"http://opi.yahoo.com/online?u=YahooUser1234&m=g&t=2\">\r\n" + " </a" ) ); + + } + + @Test + public void testPlugin() throws Exception { + Assertions.assertEquals( + "This is a private homepage done by\n" + "* * *\n" + "Dies ist eine private, nicht-kommerzielle Homepage von\n" + + "[{Text2gif width='150' height='100' \n" + " \n" + "Sebastian L. Baltes \n" + "Lange Str. 53 \n" + "44137 Dortmund \n" + " \n" + + "email: [email protected] \n" + "}]()\n", + html2wiki.translate( "This is a private homepage done by\n" + "<hr>\n" + "Dies ist eine private, nicht-kommerzielle Homepage von\n" + "<p>\n" + + "[{Text2gif width='150' height='100'\n" + "<br> <br>Sebastian L. Baltes\n" + "<br>Lange Str. 53\n" + "<br>44137 Dortmund\n" + + "<br> <br>email: [email protected]\n" + "<br>}]()\n" + "</p><p>" ) ); + + } + + @Test + public void testCSS() throws Exception { + Assertions.assertEquals( "Und niemand wird sie sehen { style=' color: rgb(255, 0, 0);' }, die", + html2wiki.translate( "<span style=\"color: rgb(255, 0, 0);\">Und niemand wird sie sehen</span>, die" ) ); + + Assertions.assertEquals( + "\nCSS class here {.information}\n\nFont styling here. { style=' color: #ff9900; font-family: arial; font-size: large;' } Some more here { style=' background-color: #ffff00;' }.\n", + html2wiki.translate( + "<div class=\"information\">CSS class here</div>\n" + "<p>Font <font face=\"Arial\" color=\"#ff9900\" size=\"5\">styling here.</font>" + + " Some <font style=\"background-color: #ffff00\">more here</font>.</p>" ) ); + + Assertions.assertEquals( "\n\nsome leading text <!---->line through this text{.strike} some trailing text { style=' text-align: center;' }\n\n", + html2wiki.translate( "<p align=\"center\">some leading text <strike>line through this text</strike> some trailing text</p>" ) ); + } + + @Test + public void testParsing() throws Exception { + Assertions.assertEquals( "Hello World!", html2wiki.translate( "Hello World!" ) ); + Assertions.assertEquals( "a", html2wiki.translate( "a" ) ); + Assertions.assertEquals( "a \nb", html2wiki.translate( "a<br/>b" ) ); + Assertions.assertEquals( " \\", html2wiki.translate( " \n\\" ) ); + Assertions.assertEquals( "[{Test Hello World!}]()", html2wiki.translate( "[{Test \n \nHello World!}]()" ) ); + Assertions.assertEquals( "``[{Test Hello World!}]()``", html2wiki.translate( "``[{Test \n \nHello World!}]()``" ) ); + Assertions.assertEquals( "``[{Test Hello World!}]()````[{Test \nHello World!}]()``[{Test Hello World!}]()[{Test Hello World!}]()", html2wiki + .translate( "``[{Test \nHello World!}]()````[{Test<br>Hello World!}]()``[{Test \n \nHello World!}]()[{Test \n \nHello World!}]()" ) ); + } + + @Test + public void testBoldAndItalic() throws Exception { + Assertions.assertEquals( "Dies ist **bold**, _italic_ und **_both_**.", html2wiki.translate( + "Dies ist <span style=\"font-weight: bold;\">bold</span>, <span style=\"font-style: italic;\">italic</span> und <span style=\"font-style: italic; font-weight: bold;\">both</span>." ) ); + + Assertions.assertEquals( "Dies ist **bold**, _italic_ und **_both_** 2.", + html2wiki.translate( "Dies ist <b>bold</b>, <i>italic</i> und <b><i>both</i></b> 2." ) ); + + Assertions.assertEquals( "Dies ist **bold**, _italic_ und **_both_** 3.", + html2wiki.translate( "Dies ist <strong>bold</strong>, <em>italic</em> und <strong><em>both</em></strong> 3." ) ); + + Assertions.assertEquals( "Wilma: _Ich m\u00f6chte hiermal in allerDeutlichkeit sagen! _", + html2wiki.translate( "Wilma: <i>Ich m\u00f6chte hier\nmal in aller\nDeutlichkeit sagen! </i>" ) ); + + } + + @Test + public void testHeading() throws Exception { + Assertions.assertEquals( "\n# Heading 1 should be translated to large heading.\n", + html2wiki.translate( "<h1>Heading 1 should be translated to large heading.</h1>" ) ); + + Assertions.assertEquals( "\n## Heading 2 should be translated to large heading.\n", + html2wiki.translate( "<h2>Heading 2 should be translated to large heading.</h2>" ) ); + + Assertions.assertEquals( "\n### Heading 3 should be translated to medium heading.\n", + html2wiki.translate( "<h3>Heading 3 should be translated to medium heading.</h3>" ) ); + + Assertions.assertEquals( "\n#### Heading 4 should be translated to small heading.\n", + html2wiki.translate( "<h4>Heading 4 should be translated to small heading.</h4>" ) ); + } + + @Test + public void testForm() throws Exception { + Assertions.assertEquals( "\n[{FormOpen form='myForm'}]()\n\n[{FormClose}]()\n", + html2wiki.translate( "<div class=\"wikiform\">\n<form name=\"myForm\"><input name=\"formname\" value=\"myForm\" type=\"hidden\">\n</div>" ) ); + + Assertions.assertEquals( "[{FormInput type='hidden' name='myHiddenField' value='myHiddenField'}]()myHiddenField", + html2wiki.translate( "<input name=\"nbf_myHiddenField\" value=\"myHiddenField\" type=\"hidden\">myHiddenField" ) ); + + Assertions.assertEquals( "[{FormInput type='checkbox' name='myCheckbox' value='myCheckbox' checked='checked'}]()myCheckbox", + html2wiki.translate( "<input checked=\"checked\" value=\"myCheckbox\" name=\"nbf_myCheckbox\" type=\"checkbox\">myCheckbox" ) ); + + Assertions.assertEquals( "[{FormInput type='radio' name='myRadioButton' value='myRadioButton'}]()myRadioButton", + html2wiki.translate( "<input name=\"nbf_myRadioButton\" value=\"myRadioButton\" type=\"radio\">myRadioButton" ) ); + + Assertions.assertEquals( "[{FormInput type='button' name='myButton' value='myButton'}]()myButton", + html2wiki.translate( "<input name=\"nbf_myButton\" value=\"myButton\" type=\"button\">myButton" ) ); + + Assertions.assertEquals( "[{FormTextarea name='myTextarea' rows='6' cols='50'}]()myTextarea", + html2wiki.translate( "<textarea cols=\"50\" name=\"nbf_myTextarea\" rows=\"6\"></textarea>myTextarea" ) ); + + Assertions.assertEquals( "[{FormSelect name='mySelectionList' value='apple;*orange;pear'}]()mySelectList", + html2wiki.translate( "<select name=\"nbf_mySelectionList\">\n" + "<option value=\"apple\">apple</option>\n" + + "<option selected=\"selected\" value=\"orange\">orange</option>\n" + "<option value=\"pear\">pear</option>\n" + + "</select>mySelectList" ) ); + + } + + @Test + public void testDefinitionList() throws Exception { + Assertions.assertEquals( "\n**Priority**: High\n\n**TODO Name**: Initialization\n\n**Requester**: John Smith\n", + html2wiki.translate( "<dl><dt><b>Priority</b></dt><dd>High</dd></dl>\n" + "<dl><dt><b>TODO Name</b></dt><dd>Initialization</dd></dl>\n" + + "<dl><dt><b>Requester</b></dt><dd>John Smith</dd></dl>\n" ) ); + + Assertions.assertEquals( "Some text here\n: (A)indented comment here\n\n: (B)another comment here\n", html2wiki.translate( + "Some text here\n<dl><dt></dt><dd>(A)indented comment here</dd></dl>\n" + "<dl><dt></dt><dd>(B)another comment here</dd></dl>\n" ) ); + + Assertions.assertEquals( "\n**New Page Name**: [{FormInput type='text' name='newPageName'}]()\n", + html2wiki.translate( "\n<dl><dt><b>New Page Name</b></dt><dd><input name=\"nbf_newPageName\" type=\"text\"></dd></dl>\n" ) ); + } + +}
