ivanceras / svgbob

Convert your ascii diagram scribbles into happy little SVG
http://ivanceras.github.io/svgbob-editor/
Apache License 2.0
3.91k stars 112 forks source link

Styles not applied in CLI version #51

Open rochecompaan opened 4 years ago

rochecompaan commented 4 years ago

First, thank you for an awesome package!

I installed a nightly build of rust and ran cargo build on a clone of master and I also tried the rewrite3-vectorize branch.

If I generate the diagram with the CLI version eg svgbob page.txt -o page.svg, none of the styles are applied. If I use the online editor at https://ivanceras.github.io/svgbob-editor/, it works fine. What could be wrong?

I use the following input:


o-> MTSF: Add First Priority

    +-------------------------------------------------------------------------------------------------------------------------------------+
    |                                                                                                                                     |
    |    LGMIM                                                                                                   Roche Compaan  LOGOUT    |
    |                                                                                                                                     |
    +-------------------------------------------------------------------------------------------------------------------------------------+
    |                                                                                                                                     |
    |    Dashboard    Trend Analysis   Assessment   Improvement Plan   Recent Activity                                  System Setup      |
    |                                                                                                                                     |
    +-------------------------------------------------------------------------------------------------------------------------------------+
    |                                                                                                                                     |
    |                                                                                                                                     |
    |    MTSF                            .------------------------------------------------------------.                                   |
    |                                    |  {em}                                                      |                                   |
    |                                    |  Add Priority                                              |                                   |
    |                                    |                                                            |                                   |
    |    .--------------------.          |  Title                                                     |                                   |
    |    | + Add Priority {b} |  ------> |                                                            |                                   |
    |    '--------------------'          |  +------------------------------------------------------+  |                                   |
    |                                    |  | PRIORITY 1: ECONOMIC TRANSFORMATION AND JOB CREATION |  |                                   |
    |                                    |  +------------------------------------------------------+  |                                   |
    |                                    |                                                            |                                   |
    |                                    |  Description                                               |                                   |
    |                                    |                                                            |                                   |
    |                                    |  +------------------------------------------------------+  |                                   |
    |                                    |  | 2024 Impact: Increase GDP between 2-3%; create 2     |  |                                   |
    |                                    |  | million new jobs especially for youth; increase      |  |                                   |
    |                                    |  | investment as a proportion of GDP to 23% (from       |  |                                   |
    |                                    |  | 18.7%).                                              |  |                                   |
    |                                    |  +------------------------------------------------------+  |                                   |
    |                                    |                                                            |                                   |
    |                                    | ---------------------------------------------------------- |                                   |
    |                                    |                                                            |                                   |
    |                                    |                                   [ Submit ]  [ Cancel ]   |                                   |
    |                                    |                                                            |                                   |
    |                                    '------------------------------------------------------------'                                   |
    |                                                                                                                                     |
    |                                                                                                                                     |
    |                                                                                                                                     |
    |                                                                                                                                     |
    +-------------------------------------------------------------------------------------------------------------------------------------+

# Legend:
b = {
    fill: lightblue;
}
em = {
    fill: yellow;
    stroke: black;
}
Melandel commented 4 years ago

I'd like to second this. I tried with the demo text for my part.

ivanceras commented 4 years ago

@rochecompaan @Melandel thanks, for reporting this issue. I'll take a look into this.

ivanceras commented 4 years ago

Unfortunately, I wasn't able to replicate this. I used the same test .bob, but it had styles on it. Can you post the used cli commands and the generated svg image?

ivanceras commented 4 years ago

@rochecompaan @Melandel I've pushed in a new commit setting the exact version of svgbob from the cli. Perhaps it would solve the issue.

Melandel commented 4 years ago

:(

Still don't have styles.

Maybe I'm doing things wrong?

Here's what I did:

Edit: I'm on Windows 10. Does that change anything?

ivanceras commented 4 years ago

Maybe the photo-viewer you are showing might now be rendering the svg correctly. Try opening the svg image using firefox or chrome.

It would help if you could post your .bob input and a screenshot, or the generated svg text. Here is what I've generated based the the input above. https://imgur.com/a/aUoYhbw

rochecompaan commented 4 years ago

I first tried on Debian installed in WSL2 and got the following SVG output for the input text I posted originally:

svgbob-test.txt

I tried on Windows 10 as well and got the following output:

svgtest-win.txt

No styling appears in Edge, Firefox or Chrome for any of the platforms.

Melandel commented 4 years ago

I tried the input above and got this in firefox on Windows 10: image

svg output ```svg PRIORITY 1: ECONOMIC TRANSFORMATION AND JOB CREATION 2024 Impact: Increase GDP between 2 3%; create 2 million new jobs especially for youth; increase investment as a proportion of GDP to 23% from 18.7% . Add Priority Title Description [ Submit ] [ Cancel ] + Add Priority MTSF: Add First Priority LGMIM Roche Compaan LOGOUT Dashboard Trend Analysis Assessment Improvement Plan Recent Activity System Setup MTSF # b Legend: { fill: lightblue; } em { fill: yellow; stroke: black; } ```
ivanceras commented 4 years ago

@Melandel , try doing a cargo update on svgbob and in svgbob_cli. It looks like Cargo.lock is included in the repo. I'm going to delete Cargo.lock in the next commits.

Melandel commented 4 years ago

I tried a cargo update on the three folders (svgbob, svgbob/svgbob and svgbob/svgbob_cli) on a fresh clone of the repo.

The issue persists :(

Melandel commented 4 years ago

My knowledge of Rust is absolutely inexistant, but I managed to find out that the css parsing fails on my machine maybe because windows newline characters cause some trouble.

Substituting

    pub fn new_line<'a>() -> Parser<'a, char, ()> {
        one_of("\n").discard()
    }

with

    pub fn new_line<'a>() -> Parser<'a, char, ()> {
        one_of("\r\n").discard()
    }

allows

impl From<&str> for CellBuffer {
    fn from(input: &str) -> Self {
        let css_styles = if let Some(loc) = input.find("# Legend:") {
            if let Ok(css_styles) = parser::parse_css_legend(&input[loc..]) {
                Some((loc, css_styles))
            } else {
                None
            }
        } else {
            None
        };
        /// [...]
    }
}

to validate parser::parse_css_legend(&input[loc..]), whereas with no substitution the code goes directly into the None branch.

However, unless my println technique is flawed (because I don't really understand anything about the syntax I'm using for the moment haha), even after substitution the variable css_styles seems to be an empty array.

Melandel commented 4 years ago

I can confirm it's an issue linked to the end-of-line characters.

I got the colors (I got the colors !! 😹) when I switch the fileformat from dos to unix.

This is a nice workaround, but I still think it would be interesting to handle dos end of line characters.

What do you think?

rochecompaan commented 4 years ago

It's working for me once I switch to Unix line endings. +1 for adding support for CRLF as well.

ivanceras commented 4 years ago

Thank you all for filing the issue and finding the root cause. I just published a new version of with support of carriage return \r . Please help me test it out.

Melandel commented 4 years ago

Hi,

I cannot confirm the fix works.

As stated above, the outcome of this code change seems to be an empty css_styles array.

Visual confirmation: image

rochecompaan commented 4 years ago

@ivanceras it's not working on the latest master.