bwanders / dokuwiki-strata

Strata - a Semi-Structured Data plugin for Dokuwiki
https://www.dokuwiki.org/plugin:strata
17 stars 8 forks source link

Implemented ODT support. #33

Closed lpaulsen93 closed 7 years ago

lpaulsen93 commented 7 years ago

A user asked for ODT support, see https://www.dokuwiki.org/plugin:odt:rendersupport#odt_initiative. This is a simple implementation. Please merge, if you like it.

bwanders commented 7 years ago

Hi there! I like the initiative, and want to help get ODT support working well. I have reviewed your PR and have one overarching comment which is, unfortunately, not something you might want to hear:

All the effort to get styles rendered correctly in the ODT output is unnecessary -- those styles are not actually there to change the display of the output, but instead to enable the javascript part of the plugin to handle the data in an intelligent manner.

Because of this style fiddling the current PR code has a lot of duplication between the xhtml and odt output formats, which will increase the effort needed to maintain the code. If the aim is to have support for well-behaved ODT format output, this goal can be achieved by a few tweaks of the base code to support both xhtml and odt at the same time.

Looking what I have learned about ODT support from the approach you have taken, I think the way to get ODT support working for Strata, with the least amount of effort and friction would be this:

I am willing to make a branch with the initial changes to the codebase, if you are willing to test and tweak that branch with a PR -- that way we combine our respective strengths. Will that work for you?

lpaulsen93 commented 7 years ago

Sounds great for me. Thanks for the detailed feedback.

I did not want to change to much in the original code but if you are going to do some reviewing, then of course it's a good idea to remove as much code duplication as possible. I'm not using the strata plugin myself so I need assistance for testing that everything works as usual.

I do not understand which spans are not required. Can you list these? Some spans could be interesting for the styling/look of the data, or not?

bwanders commented 7 years ago

Ok, I will branch a first attempt in the coming weekend (i.e., april 8th and 9th).

Right now, none of the spans are actually used for styling in the xhtml output, they are purely there as containers for the text so the javascript can extract it cleanly on the client. I suggest we look into adding in some span support after we know that we have the basics working -- that way we'll be able to merge in the basic support faster.

lpaulsen93 commented 7 years ago

:thumbsup: Just leave me a message here when the branch is ready.

bwanders commented 7 years ago

So, I went over the basics in commit bad4e15f8e1347a1ff427951bbf0c1dc73a804be to the feature-odt branch (apologies for the bunch of fixed errant white-space all around, which makes the diff somewhat less readable...)

I tested it against the current odt renderer release (2017-04-06) and everything seems to work ok. So if you can check that there's nothing fishy going on with the renderer, I can probably merge this soon. The biggest problem seems to be internal links within the same page. (i.e., a header called Foo and a link to #foo rendered through the strata ref type, which netted me a jump to the top of the document. Not sure if that's something I can fix from within strata though...)

(If you see anything that stands out as Not The Idiomatic ODT Way™ drop me a line here, or place a PR against the branch ^_^)

lpaulsen93 commented 7 years ago

Looks good to me :thumbsup:

The biggest problem seems to be internal links within the same page. (i.e., a header called Foo and a link to #foo rendered through the strata ref type, which netted me a jump to the top of the document. Not sure if that's something I can fix from within strata though...)

Internal links to headlines should automatically be converted to ODT links. That means it should work if you reference a headline. How can I created such a reference? I would like to test it to see if there is a issue in the ODT plugin.

bwanders commented 7 years ago

I tested with the following page (I am sorry don't have time to make a proper minimum working example):

====== Test page ======

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus in porta erat. Nunc justo erat, dignissim et blandit viverra, congue sit amet neque. Sed risus ex, congue in ligula ac, venenatis aliquet ipsum. Vestibulum ultricies ut turpis sit amet posuere. Mauris accumsan volutpat tortor ac dignissim. Etiam eget mi ipsum. Donec efficitur metus metus, nec suscipit erat faucibus sit amet:

<list ?p ?o>
?p is a: person
?p Occupation: ?o
</list>

Morbi fermentum leo erat, non tristique purus tristique a. Cras gravida, ligula vel tincidunt mattis, justo elit varius leo, ac maximus est sem ut arcu. Morbi sit amet dui in orci cursus imperdiet. Pellentesque sagittis felis sit amet mi mollis, at dictum est sagittis. Pellentesque libero odio, vestibulum ut luctus et, vestibulum sit amet mi.

===== Errors =====

<list ?p ?o>
?p is a: person
?p failure
?p Occupation: ?o
</list>

===== Infos =====
~~INFO:stratatypes~~
~~INFO:strataaggregates~~
===== Nullam =====

<data person test_data #Nullam>
Full Name: Nullam Vivamus
Occupation: Hypothetical Personage
Date [date]: 2017-04-08
</data>

Ullamcorper lorem. Vivamus ac turpis sit amet justo scelerisque ultricies non sed est. Vivamus euismod consequat nibh, nec varius dui vestibulum nec. Sed egestas nibh condimentum risus ultricies porttitor. Proin pellentesque, mauris eget scelerisque semper, lorem dolor efficitur ante, at tristique risus mauris iaculis nulla. Quisque arcu odio, tempor non leo a, ultricies vulputate nunc. Vestibulum sed dictum libero.

In hac habitasse platea dictumst. Vivamus eros enim, eleifend vel nisl eu, pretium fermentum nisl. Suspendisse mattis mi vel suscipit mattis. Sed euismod, nibh id rutrum sodales, libero nisi volutpat velit, sit amet laoreet tortor orci eget mi. Maecenas faucibus erat sit amet mattis tempor. Maecenas a dapibus lacus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Etiam non facilisis elit, ut molestie nunc. Nam neque velit, faucibus at placerat ac, convallis id quam. Curabitur quis enim vel libero tristique porttitor. Vestibulum id turpis sapien. Etiam nec consectetur mauris. Morbi facilisis, nulla a tempus varius, est leo facilisis justo, a laoreet felis orci quis urna. Suspendisse vehicula eros convallis, dapibus mi et, ullamcorper sapien. Fusce in nulla iaculis, elementum eros quis, convallis metus. Sed vel venenatis mauris.

Vestibulum lobortis efficitur gravida. Vivamus feugiat sapien sed mauris ultrices hendrerit. Nullam dapibus nibh nisl, in bibendum purus molestie in. Aenean a nisl eget mi mollis cursus. Mauris eget risus sed magna posuere consectetur. Nam magna nunc, ullamcorper vel arcu id, scelerisque scelerisque felis. Nulla ornare in orci in scelerisque. In iaculis massa sapien, mattis aliquet mi malesuada vel. In eget dui id nisl convallis malesuada quis a ex. Nullam finibus luctus quam, vel hendrerit lorem eleifend vitae.

===== Donec =====

Malesuada elementum lorem et pretium. Cras lacinia tincidunt nibh, a tincidunt nibh imperdiet at. Integer gravida turpis est, vitae feugiat dolor fermentum eget.

<table ?p "Person" ?fn "Full Name" ?o "Occupation">
?p is a: person
?p Full Name: ?fn
?p Occupation: ?o
</table>

Duis dapibus orci nisl, blandit dignissim ex fringilla ac. Praesent vel volutpat nunc, sed accumsan tortor. Nulla facilisi. Cras tristique erat non pretium pretium. Aenean non massa consequat, rhoncus mauris at, consectetur arcu. Cras sed libero finibus, pharetra lorem in, bibendum dui. Phasellus viverra dolor orci, in mollis lectus lobortis vitae. Phasellus in dolor non dolor consectetur iaculis at non libero. Pellentesque ultrices urna vel sem cursus, at consequat risus feugiat. Nullam consectetur diam non finibus semper. 

Because the data entry block for the Nullam person is on the same page as the table generated in the Donec header, it produces a link to the same page. The fact that it links to the same page is picked up by the ODT renderer, but the link jumps to the top of the document. (Maybe the trick at https://github.com/bwanders/dokuwiki-strata/blob/master/types/ref.php#L30 trips it up?)

This is the exact page that triggers the problem. But I'm reasonably sure that the Errors and Infos sections can be dropped without problem for ease of testing.

lpaulsen93 commented 7 years ago

Ok, the link to "nullam" was indeed a problem in the ODT plugin. I just fixed it in https://github.com/LarsGit223/dokuwiki-plugin-odt/commit/b197607a08c56ab7d681c600b4810cdb830745d3 (master branch).

lpaulsen93 commented 7 years ago

I also notices a minor issue with my test page:

~~NOCACHE~~

====== Foo ======

Test123:

<data person>
-- Simple field-value pairs
Full Name: Jane Maria Doe
Address:

-- Types and Type Hint
Birthday [date]: 1982-7-23
Birthplace [page::places]: Springfield

-- Multiple values
Contact [link]*: j.doe@example.com, http://www.facebook.com/Jane-Doe
Contact [link]: jane.doe@workmail.com
</data>

<table ?p "Person" ?b "Birthday">
?p is a: person
?p Birthday [date]: ?b
?b < 1990-1-1
</table>

<list ?person ?contact>
?person is a: person
?person Contact [link]: ?contact
</list>

~~INFO:stratatypes~~

<data person>
Full Name: John Doe
Age: 24
Contact [link]: john.doe@example.org
Friends [ref]*: Alice, Bob
</data>

This generates linked tables ("next" and "previous" links). This is actually not working in the ODT document. There is also actually no API function to create an own bookmark from within a plugin.

bwanders commented 7 years ago

I have opened #36, which supersedes this PR.