Skip to content

Commit

Permalink
[XML] Improve the fidelity of DocBook flavor export
Browse files Browse the repository at this point in the history
Map 'class' attribute to 'role'
  • Loading branch information
0x8000-0000 committed Apr 22, 2020
1 parent 3ffdd67 commit fe1a489
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group 'net.signbit.samx'
version '0.3.7'
version '0.3.8'

sourceCompatibility = 1.8

Expand Down
18 changes: 10 additions & 8 deletions src/main/java/net/signbit/samx/AttributeVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,26 +84,28 @@ public Void visitReferenceAttr(SamXParser.ReferenceAttrContext ctx)
return null;
}

private boolean wantsClassAttributes()
{
return (! docBookMode) && (! classAttributes.isEmpty());
}

@Override
public String toString()
{
StringBuilder builder = new StringBuilder();

boolean isEmpty = true;

if (wantsClassAttributes() || (idAttribute != null) || (nameAttribute != null))
if ((! classAttributes.isEmpty()) || (idAttribute != null) || (nameAttribute != null))
{
builder.append(' ');
}

if (wantsClassAttributes())
if (! classAttributes.isEmpty())
{
builder.append("class=\"");
if (docBookMode)
{
builder.append("role=\"");
}
else
{
builder.append("class=\"");
}
boolean firstElement = true;
for (String className : classAttributes)
{
Expand Down
14 changes: 7 additions & 7 deletions src/test/resources/grids/simple-docbook.samx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<article xmlns="http://docbook.org/ns/docbook" xmlns:xl="http://www.w3.org/1999/xlink" version="5.1">
<para>This document contains a grid.</para>
<table xml:id="the-grid">
<table role="fancy" xml:id="the-grid">
<title>Example table</title>
<tgroup cols="6">
<thead>
<row>
<row role="header">
<entry>Name</entry>
<entry>Position</entry>
<entry><phrase>Office</phrase></entry>
<entry><phrase>Age</phrase></entry>
<entry><phrase role="location">Office</phrase></entry>
<entry><phrase role="numeric">Age</phrase></entry>
<entry>Start date</entry>
<entry>Salary</entry>
</row>
Expand All @@ -23,7 +23,7 @@
<entry>2008/11/28</entry>
<entry>$162,700</entry>
</row>
<row>
<row role="highlight">
<entry>Angelica Ramos</entry>
<entry>Chief Executive Officer (CEO)</entry>
<entry>London</entry>
Expand All @@ -42,7 +42,7 @@
<row>
<entry>Bradley Greer</entry>
<entry>Software Engineer</entry>
<entry><phrase>London</phrase></entry>
<entry><phrase role="expensive">London</phrase></entry>
<entry>41</entry>
<entry>2012/10/13</entry>
<entry>$132,000</entry>
Expand All @@ -55,7 +55,7 @@
<entry>2011/06/07</entry>
<entry>$206,850</entry>
</row>
<row>
<row role="highlight extra">
<entry>Brielle Williamson</entry>
<entry>Integration Specialist</entry>
<entry>New York</entry>
Expand Down

0 comments on commit fe1a489

Please sign in to comment.