Roberto M. wrote:

Im strugling with a conversion to epub (W2X version
1.2.3).

$: w2x-pro-1_2_3/bin/w2x -vv -o epub -p convert.charset UTF-8 -p
epub.split-before-level 6 -p epub.use-id-as-filename no -p
epub.identifier "epub" -p set-column-number yes -p version 5.0 test.docx
test.epub

VERBOSE: Converting "test.docx" to XHTML...
DEBUG: convert.xhtml-file=/tmp/test__epub/test.xhtml convert.version=1.1
convert.create-mathml-object=no convert.charset=UTF-8
convert.lower-case-resource-names=true
VERBOSE: Editing XHTML document using
"XMLmind/w2x-pro-1_2_3/xed/main-styled.xed"...
DEBUG: edit.do.expand-tabs=""
edit.xed-url-or-file=file:XMLmind/w2x-pro-1_2_3/xed/main-styled.xed
edit.remove-pis.except=counter
DEBUG: Loading script "file:XMLmind/w2x-pro-1_2_3/xed/main-styled.xed"...
DEBUG: Loading script "file:XMLmind/w2x-pro-1_2_3/xed/init-styles.xed"...
DEBUG: Loading script "file:XMLmind/w2x-pro-1_2_3/xed/title-styled.xed"...
DEBUG: Loading script "file:XMLmind/w2x-pro-1_2_3/xed/remove-pis.xed"...
DEBUG: Loading script "file:XMLmind/w2x-pro-1_2_3/xed/borders.xed"...
ERROR: Conversion has failed:
file:XMLmind/w2x-pro-1_2_3/xed/borders.xed:352:6: error in action
"group": missing attribute "g:container" for element
/html:html[1]/html:body[1]/html:p[34]
file:XMLmind/w2x-pro-1_2_3/xed/borders.xed:352:6: error in action
"group": missing attribute "g:container" for element
/html:html[1]/html:body[1]/html:p[34]

Your test.docx (which is just fine) has triggered a bug in W2X_install_dir/xed/borders.xed. Sorry for that.

Fortunately, this one is easy to fix. Please proceed as follows:

1) Delete W2X_install_dir/bin/w2x_all.jar because this self-contained jar includes its own copy of buggy borders.xed.

2) In folder W2X_install_dir/xed/, please replace stock borders.xed by attached file.

That's it.




The idea is to output semantic epub (using epub1_1 flag) *with* CSS
style file... like version 1.2.1 do with this flag.


I'm sorry but there is no way to get semantic EPUB with the CSS style file generated out of MS-Word specified styles.

A) You can generate non-semantic, styled, EPUB with the CSS style file generated out of MS-Word specified styles. Example:

w2x -o epub test.docx test.epub

B) You can generate non-semantic styled, EPUB with custom CSS styles based on the MS-Word specified styles. Example:

w2x -o epub \
   -pu edit.finish-styles.custom-styles-url-or-file customized.css \
   test.docx test.epub

C) You can semantic EPUB with your own, corporate, CSS styles. Example:

w2x -o epub1_1 \
   -pu edit.finish-styles.custom-styles-url-or-file mycorpstyles.css \
   test.docx test.epub

The command-line you currently use corresponds to (A). Options "-p convert.charset UTF-8 -p set-column-number yes -p version 5.0" are not useful.

(:
 : Copyright (c) 2017 XMLmind Software. All rights reserved.
 : 
 : Author: Hussein Shafie
 : 
 : This file is part of the XMLmind W2X project.
 : For conditions of distribution and use, see the accompanying legal.txt file.
 :)

namespace "http://www.w3.org/1999/xhtml";;
namespace html = "http://www.w3.org/1999/xhtml";;
namespace g = "urn:x-mlmind:namespace:group";

(: Collapse the borders of adjacent paragraphs having identical borders. :)

macro updateDirectStyles(left, right, backgroundColor) {
    (: Named styles pb--first,middle,last cannot be used to override 
       direct styles, if any. :)

    if get-style("border-top-style") {
        set-style("border-top-style", "none");
    }

    if get-style("border-bottom-style") {
        set-style("border-bottom-style", "none");
    }

    if get-style("border-left-style") {
        set-style("border-left-style", "none");
    }

    if get-style("border-right-style") {
        set-style("border-right-style", "none");
    }

    if get-style("padding-top") {
        set-style("padding-top", "0pt");
    }

    if get-style("padding-bottom") and get-class("pb--last") {
        set-style("padding-bottom", "0pt");
    }

    if get-style("padding-left") {
        set-style("padding-left", "0pt");
    }

    if get-style("padding-right") {
        set-style("padding-right", "0pt");
    }

    if get-style("margin-top") and get-class("pb--first") {
        set-style("margin-top", "0pt");
    }

    if get-style("margin-bottom") and get-class("pb--last") {
        set-style("margin-bottom", "0pt");
    }

    if $backgroundColor != '' and $backgroundColor != 'transparent' {
        set-variable("backgroundColor2", lookup-style("background-color"));
        if $backgroundColor2 = '' or $backgroundColor2 = 'transparent' {
            (: 'transparent' is relative to the parent element.
               Now that its (future) parent is a colored div, 
               'transparent' means the background color of 
               the (future) grand-parent element. :)

            set-variable("backgroundColor2", 
                          lookup-style("background-color", parent::*));
            if $backgroundColor2 = '' or $backgroundColor2 = 'transparent' {
                set-variable("backgroundColor2", "#FFFFFF");
            }
            set-style("background-color", $backgroundColor2);
        }
    }

    set-variable("left2", lookup-length("margin-left"));
    if string($left2) = "NaN" {
        set-variable("left2", 0);
    }
    if $left2 > $left {
        set-style("margin-left", concat($left2 - $left, "pt"));
    } elseif get-style("margin-left") != '' {
        set-style("margin-left", "0pt");
    }
}

for-each /html/body//p {
    if @g:id {
        (: Already marked. :)
        continue();
    }

    set-variable("borderTopStyle", lookup-style("border-top-style"));
    set-variable("borderBottomStyle", lookup-style("border-bottom-style"));
    set-variable("borderLeftStyle", lookup-style("border-left-style"));
    set-variable("borderRightStyle", lookup-style("border-right-style"));

    if ($borderTopStyle = '' or $borderTopStyle = 'none') and
       ($borderBottomStyle = '' or $borderBottomStyle = 'none') and
       ($borderLeftStyle = '' or $borderLeftStyle = 'none') and
       ($borderRightStyle = '' or $borderRightStyle = 'none') {
        continue();
    }

    set-variable("borderBetween", lookup-style("-ms-border-between"));
    if $borderBetween != '' and $borderBetween != 'none' {
        continue();
    }

    set-variable("borderTopColor", lookup-style("border-top-color"));
    set-variable("borderBottomColor", lookup-style("border-bottom-color"));
    set-variable("borderLeftColor", lookup-style("border-left-color"));
    set-variable("borderRightColor", lookup-style("border-right-color"));

    set-variable("borderTopWidth", lookup-style("border-top-width"));
    set-variable("borderBottomWidth", lookup-style("border-bottom-width"));
    set-variable("borderLeftWidth", lookup-style("border-left-width"));
    set-variable("borderRightWidth", lookup-style("border-right-width"));

    set-variable("paddingTop", lookup-style("padding-top"));
    set-variable("paddingBottom", lookup-style("padding-bottom"));
    set-variable("paddingLeft", lookup-style("padding-left"));
    set-variable("paddingRight", lookup-style("padding-right"));

    set-variable("backgroundColor", lookup-style("background-color"));

    set-variable("indent", lookup-length("text-indent"));
    if string($indent) = "NaN" {
        set-variable("indent", 0);
    }
    set-variable("left", lookup-length("margin-left"));
    if string($left) = "NaN" {
        set-variable("left", 0);
    }
    if $indent < 0 {
        set-variable("left", $left + $indent);
    }

    set-variable("right", lookup-length("margin-right"));
    if string($right) = "NaN" {
        set-variable("right", 0);
    }

    set-variable("boxGroupId", generate-id());

    for-each following-sibling::* {
        if not(self::p and
               $borderTopStyle = lookup-style("border-top-style") and
               $borderBottomStyle = lookup-style("border-bottom-style") and
               $borderLeftStyle = lookup-style("border-left-style") and
               $borderRightStyle = lookup-style("border-right-style") and
               $borderTopColor = lookup-style("border-top-color") and
               $borderBottomColor = lookup-style("border-bottom-color") and
               $borderLeftColor = lookup-style("border-left-color") and
               $borderRightColor = lookup-style("border-right-color") and
               $borderTopWidth = lookup-style("border-top-width") and
               $borderBottomWidth = lookup-style("border-bottom-width") and
               $borderLeftWidth = lookup-style("border-left-width") and
               $borderRightWidth = lookup-style("border-right-width") and
               $paddingTop = lookup-style("padding-top") and
               $paddingBottom = lookup-style("padding-bottom") and
               $paddingLeft = lookup-style("padding-left") and
               $paddingRight = lookup-style("padding-right")) {
            break();
        }

        set-variable("borderBetween2", lookup-style("-ms-border-between"));
        if $borderBetween2 != '' and $borderBetween2 != 'none' {
            break();
        }

        set-variable("indent2", lookup-length("text-indent"));
        if string($indent2) = "NaN" {
            set-variable("indent2", 0);
        }
        set-variable("left2", lookup-length("margin-left"));
        if string($left2) = "NaN" {
            set-variable("left2", 0);
        }
        if $indent2 < 0 {
            set-variable("left2", $left2 + $indent2);
        }

        set-variable("right2", lookup-length("margin-right"));
        if string($right2) = "NaN" {
            set-variable("right2", 0);
        }

        if $left != $left2 or $right != $right2 {
            break();
        }

        set-attribute("g:id", $boxGroupId);
    }

    set-variable("boxGroupMembers", following-sibling::p[@g:id = $boxGroupId]);
    if count($boxGroupMembers) > 0 or 
       get-rule(concat(".", get-class("/^n-/"), ":before"), "float") {
        (: Reason: a box around a single numbered paragraph is rendered 
           around the body of the paragraph and not around 
           its floated number/label; which differs from what does MS-Word. :)

        set-attribute("g:id", $boxGroupId);
        add-class("pb--first");

        set-variable("boxGroupMembers", . | $boxGroupMembers);

        set-variable("boxGroupLast", $boxGroupMembers[last()]);
        add-class("pb--last", "", $boxGroupLast);

        for-each $boxGroupMembers {
            if get-class("/^pb--/") = '' {
                add-class("pb--middle");
            }

            updateDirectStyles($left, $right, $backgroundColor);
        }

        set-variable("boxGroupDiv", "div class='role-box' style='");

        if $borderTopStyle {
            set-variable("boxGroupDiv", 
                         concat($boxGroupDiv, " border-top-style: ", 
                                $borderTopStyle, ";"));
        }
        if $borderBottomStyle {
            set-variable("boxGroupDiv", 
                         concat($boxGroupDiv, " border-bottom-style: ", 
                                $borderBottomStyle, ";"));
        }
        if $borderLeftStyle {
            set-variable("boxGroupDiv", 
                         concat($boxGroupDiv, " border-left-style: ", 
                                $borderLeftStyle , ";"));
        }
        if $borderRightStyle {
            set-variable("boxGroupDiv", 
                         concat($boxGroupDiv, " border-right-style: ", 
                                $borderRightStyle, ";"));
        }

        if $borderTopColor {
            set-variable("boxGroupDiv", 
                         concat($boxGroupDiv, " border-top-color: ", 
                                $borderTopColor, ";"));
        }
        if $borderBottomColor {
            set-variable("boxGroupDiv", 
                         concat($boxGroupDiv, " border-bottom-color: ", 
                                $borderBottomColor, ";"));
        }
        if $borderLeftColor {
            set-variable("boxGroupDiv", 
                         concat($boxGroupDiv, " border-left-color: ", 
                                $borderLeftColor, ";"));
        }
        if $borderRightColor {
            set-variable("boxGroupDiv", 
                         concat($boxGroupDiv, " border-right-color: ", 
                                $borderRightColor, ";"));
        }

        if $borderTopWidth {
            set-variable("boxGroupDiv", 
                         concat($boxGroupDiv, " border-top-width: ", 
                                $borderTopWidth, ";"));
        }
        if $borderBottomWidth {
            set-variable("boxGroupDiv", 
                         concat($boxGroupDiv, " border-bottom-width: ", 
                                $borderBottomWidth, ";"));
        }
        if $borderLeftWidth {
            set-variable("boxGroupDiv", 
                         concat($boxGroupDiv, " border-left-width: ", 
                                $borderLeftWidth, ";"));
        }
        if $borderRightWidth {
            set-variable("boxGroupDiv", 
                         concat($boxGroupDiv, " border-right-width: ", 
                                $borderRightWidth, ";"));
        }

        if $paddingTop {
            set-variable("boxGroupDiv", 
                         concat($boxGroupDiv, " padding-top: ", 
                                $paddingTop, ";"));
        }
        if $paddingBottom {
            set-variable("boxGroupDiv", 
                         concat($boxGroupDiv, " padding-bottom: ", 
                                $paddingBottom, ";"));
        }
        if $paddingLeft {
            set-variable("boxGroupDiv", 
                         concat($boxGroupDiv, " padding-left: ", 
                                $paddingLeft, ";"));
        }
        if $paddingRight {
            set-variable("boxGroupDiv", 
                         concat($boxGroupDiv, " padding-right: ", 
                                $paddingRight, ";"));
        }

        if $backgroundColor {
            set-variable("boxGroupDiv", 
                         concat($boxGroupDiv, " background-color: ", 
                                $backgroundColor, ";"));
        }

        set-variable("marginTop", lookup-style(" margin-top"));
        if $marginTop {
            set-variable("boxGroupDiv", 
                         concat($boxGroupDiv, "margin-top: ", 
                                $marginTop, ";"));
        }

        set-variable("marginBottom",
                     lookup-style("margin-bottom", $boxGroupLast));
        if $marginBottom {
            set-variable("boxGroupDiv", 
                         concat($boxGroupDiv, " margin-bottom: ", 
                                $marginBottom, ";"));
        }

        set-variable("boxGroupDiv", 
                     concat($boxGroupDiv, " margin-left: ", 
                            $left, "pt;"));

        set-variable("boxGroupDiv", 
                     concat($boxGroupDiv, " margin-right: ", 
                            $right, "pt;"));

        (: CSS counters are "self-nesting". Resetting a counter in a
           descendant element or pseudo-element automatically creates a new
           instance of the counter. 
           Now that a numbered paragraph has a (future) div parent,
           it no longer creates a new instance of the counter. :)

        set-variable("counterReset",
                     lookup-style("counter-reset", $boxGroupLast));
        if $counterReset {
            set-variable("boxGroupDiv", 
                         concat($boxGroupDiv, " counter-reset: ", 
                                $counterReset, ";"));
        }

        set-attribute("g:container", concat($boxGroupDiv, "'"));
    }
}

group();

if defined("boxGroupLast") {
    set-variable("rule", "border-top-style: none; border-bottom-style: none; 
border-left-style: none; border-right-style: none; padding-top: 0pt; 
padding-left: 0pt; padding-right: 0pt; margin-left: 0pt; margin-right: 0pt;");

    add-rule(".pb--first", "", 
             concat($rule, " margin-top: 0pt;"));
    add-rule(".pb--middle", "", $rule);
    add-rule(".pb--last", "",
             concat($rule, " padding-bottom: 0pt; margin-bottom: 0pt;"));
}
--
XMLmind Word To XML Support List
[email protected]
http://www.xmlmind.com/mailman/listinfo/w2x-support

Reply via email to