Skip to content

Commit

Permalink
Add get-html-body function.
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Nov 14, 2022
1 parent fb242fe commit a57c5e4
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 3 deletions.
Binary file renamed lib/unittest-1.2.jar → lib/unittest-1.3.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This file is part of the DITA-OT Unit Test Plug-in project.
See the accompanying LICENSE file for applicable licenses.
-->
<plugin id="fox.jason.unit-test" version="2.1.1">
<plugin id="fox.jason.unit-test" version="2.2.0">

<transtype desc="Runs an antro ANT profiling report" name="antro">
<param
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>fox.jason</groupId>
<artifactId>unittest</artifactId>
<version>1.2</version>
<version>1.3</version>

<dependencies>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion resource/antlib.xml
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@

<taskdef
resource="fox/jason/unittest/antlib.xml"
classpath="${dita.dir}/plugins/fox.jason.unit-test/lib/unittest-1.2.jar"
classpath="${dita.dir}/plugins/fox.jason.unit-test/lib/unittest-1.3.jar"
/>

</antlib>
34 changes: 34 additions & 0 deletions src/fox/jason/unittest/tasks/FindBodyTask.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* This file is part of the DITA-OT Unit Test Plug-in project.
* See the accompanying LICENSE file for applicable licenses.
*/

package fox.jason.unittest.tasks;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;

// Task to extract the string between <article> tags.

public class FindBodyTask extends Task {

/**
* Creates a new <code>FindBodyTask</code> instance.
*/
public FindBodyTask() {
super();
}

/**
* Method execute.
*
* @throws BuildException if something goes wrong
*/
@Override
public void execute() {
String input = getProject().getProperty("htmlSource");
int start = input.indexOf("<body");
int end = input.indexOf("</body>") + 7;
getProject().setProperty("fragment", input.substring(start, end));
}
}
31 changes: 31 additions & 0 deletions src/main/resources/fox/jason/unittest/antlib.xml
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,28 @@
</sequential>
</macrodef>

<!--
Extract the <body>from the input HTML.
@param dir - the source directory
@param from - the source file to extract a fragment from
@param to - the file to write to
-->
<macrodef name="get-html-body">
<attribute default="${output.dir}/html" name="dir"/>
<attribute name="from"/>
<attribute default="${output.dir}/fragment.html" name="to"/>
<sequential>
<local name="htmlSource"/>
<local name="fragment"/>
<loadfile failonerror="true" property="htmlSource" srcfile="@{dir}/@{from}"/>
<find-body/>

<!-- strip out comments and save comments only to a separate file -->
<echo file="@{to}" message="${fragment}"/>
</sequential>
</macrodef>

<!--
Extract the string between <article> tags.
-->
Expand All @@ -248,6 +270,15 @@
onerror="ignore"
/>

<!--
Extract the string between <Body> tags.
-->
<taskdef
classname="fox.jason.unittest.tasks.FindBodyTask"
name="find-body"
onerror="ignore"
/>


<!--
Obtain a test resource from any of the following:
Expand Down

0 comments on commit a57c5e4

Please sign in to comment.