Comments (3)
Before doing anything in the Java space I played with building an extension in Ruby that would accept the widths.
I had to do this:
test 'should create table with width' do
input = 'table::[]'
begin
Asciidoctor::Extensions.register do
block_macro :table do
process do |parent, target, args|
table = Asciidoctor::Table.new(parent, {})
col1 = Asciidoctor::Table::Column.new(table, 0)
table.columns << col1
col2 = Asciidoctor::Table::Column.new(table, 1)
table.columns << col2
col1.set_attr 'width', 2
col2.set_attr 'width', 3
table.assign_column_widths(width_base=5, autowidth_cols=nil)
table.rows.body << [
Asciidoctor::Table::Cell.new(col1, 'first'),
Asciidoctor::Table::Cell.new(col2, 'second')
]
table.set_attr 'rowcount', table.rows.body.length
table
end
end
end
output = convert_string_to_embedded input
assert_equal output, <<~EOM.chomp
<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col width="40%">
<col width="60%">
</colgroup>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">first</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">second</p></td>
</tr>
</tbody>
</table>
EOM
ensure
Asciidoctor::Extensions.unregister_all
end
end
(Please excuse if any of my Ruby art is making your eyes bleed)
If we just want to mimic the same API in AsciidoctorJ we could just add a method Table.assignColumnWidths()
.
This would iterate over all existing columns, and sum up the widths that are positive, and collect the columns with a negative width.
Then it would call the Ruby method
table.assign_column_widths(width_base=sum of positive widths, autowidth_cols=[columns with negative width])
I think I would prefer this over doing anything implicitly.
from asciidoctorj.
#1270 demonstrates this attempt and it seems to do the trick.
// Create the table
Table table = createTable(parent)
table.grid = 'rows'
table.title = "Github contributors of $target"
// Create the columns 'Login' and 'Contributions'
Column avatarColumn = createTableColumn(table, 0)
avatarColumn.width = 1
Column loginColumn = createTableColumn(table, 1)
loginColumn.width = 2
Column contributionsColumn = createTableColumn(table, 2)
contributionsColumn.width = 2
contributionsColumn.horizontalAlignment = Table.HorizontalAlignment.CENTER
table.columns << avatarColumn
table.columns << loginColumn
table.columns << contributionsColumn
table.assignColumnWidths()
from asciidoctorj.
I think I would prefer this over doing anything implicitly.
Seems reasonable to me!
from asciidoctorj.
Related Issues (20)
- Remove deprecated methods from `ast` package HOT 3
- included jruby version is vulnerable due to snakeyaml dependency HOT 3
- release 3.0.0-alpha.1 is gravely incompatible with earlier releases HOT 11
- 'UnsupportedOperationException' when passing immutable Map as options to 'createPhraseNode' HOT 1
- Use always latest versions in distribution HOT 3
- Ensure AsciidoctorJ version is returned always in CLI
- exception containing itself as nested exception, causing maven endless loop HOT 7
- feature request: render asciidoc to markdown HOT 3
- -s CLI option should be changed to -e to align with Asciidoctor
- Automatic-Module-Name is undefined in MANIFEST file HOT 4
- CLI should set :mkdirs option by default HOT 7
- Custom Macro HOT 1
- setContext not exposed in API HOT 1
- Include processor with all attributes resolution HOT 2
- highlight.js version 9 used by AsciiDoctorJ needs update as it is out of support HOT 2
- problem parsing latex equation to pdf or epub files HOT 3
- Invalid 'backend' attribute HOT 2
- Please clarify Preprocessor documentation HOT 9
- An error occurred when creating an instance of 'asciidoctor' while running the program on Azure Service[Web App]. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from asciidoctorj.