Skip to content

Commit

Permalink
Updated decode handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jeppefrandsen committed Aug 28, 2020
1 parent d806997 commit b8b6511
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017 Jeppe Frandsen
Copyright (c) 2020 Jeppe Frandsen

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Usage of ./gravizool:
### Workflow

* Decode the Markdown file: `gravizool -d README.md`
* Change the Markdown file. The [Atom](http://atom.io) editor supports on the fly Markdown rendering (right click on the file and select "Markdown Preview")
* Change the Markdown file. Both [VS Code](https://code.visualstudio.com) and [Atom](http://atom.io) editor supports on the fly Markdown rendering (right click on the file and select "Markdown Preview")
* Fix the Markdown file in case of rendering issues: `gravizool -f README.md`
* Encode the Markdown file again: `gravizool -e README.md`
* Commit to GitHub
Expand All @@ -34,36 +34,40 @@ README.md files can be viewed in pull requests by pressing the "View" button und
If we add the [Gravizo](http://gravizo.com) example below using [plantuml](http://plantuml.com) syntax to a README.md it will not render in e.g. [Atom](http://atom.io) due to [Gravizo incompatibilities](http://www.gravizo.com/#incompatibilities):

```
![](https://g.gravizo.com/svg?
<img src='https://g.gravizo.com/svg?
@startuml
class FooBar {
String foo
void bar()
}
@enduml)
@enduml
'>
```

To fix these issues use the gravizool fix (-f) option which will convert the example to the following and make it render in e.g. [Atom](http://atom.io):
To fix these issues use the gravizool fix (-f) option which will convert the example to the following and make it render:

```
![](https://g.gravizo.com/svg?;
<img src='https://g.gravizo.com/svg?;
@startuml;
class FooBar {;
String foo;
void bar%28%29;
void bar();
};
@enduml)
@enduml
'>
```

Before uploading the README.md to GitHub it needs to be encoded with the gravizool encode (-e) option which will convert the example to:

```
![](https://g.gravizo.com/svg?%3B%0A%40startuml%3B%0Aclass%20FooBar%20{%3B%0A%20%20String%20foo%3B%0A%20%20void%20bar%28%29%3B%0A}%3B%0A%40enduml)
<img src='https://g.gravizo.com/svg?%3B%0A%40startuml%3B%0Aclass%20FooBar%20{%3B%0A%20%20String%20foo%3B%0A%20%20void%20bar%28%29%3B%0A}%3B%0A%40enduml
'>
```

The example will now be rendered on GitHub and can be seen directly in e.g. the pull request:

![](https://g.gravizo.com/svg?%3B%0A%40startuml%3B%0Aclass%20FooBar%20{%3B%0A%20%20String%20foo%3B%0A%20%20void%20bar%28%29%3B%0A}%3B%0A%40enduml)
<img src='https://g.gravizo.com/svg?%3B%0A%40startuml%3B%0Aclass%20FooBar%20{%3B%0A%20%20String%20foo%3B%0A%20%20void%20bar%28%29%3B%0A}%3B%0A%40enduml
'>

### Limitations

Expand Down
6 changes: 3 additions & 3 deletions gravizool.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ import (
"strings"
)

const gravizoolVersion = "1.0.4"
const gravizoolVersion = "1.0.5"

const gravizoBegin string = ".gravizo.com/svg?"
const gravizoEnd string = "enduml"

var gravizoEncode = strings.NewReplacer(";", "%3B", " ", "%20", "\n", "%0A", "@", "%40",
"(", "%28", ")", "%29", "*", "%2A", "\\", "%5C", "<", "%3C", ">", "%3E", "\"", "%22")
var gravizoDecode = strings.NewReplacer("%3B", ";", "%20", " ", "%0A", "\n", "%40", "@",
"%2A", "*", "%5C", "\\")
var gravizoFixEncode = strings.NewReplacer("\n", ";\n", "(", "%28", ")", "%29", "<", "%3C", ">", "%3E")
"%28", "(", "%29", ")", "%2A", "*", "%5C", "\\", "%3C", "<", "%3E", ">", "%22", "\"")
var gravizoFixEncode = strings.NewReplacer("\n", ";\n")
var gravizoFixDecode = strings.NewReplacer(";", "")

func check(err error) {
Expand Down

0 comments on commit b8b6511

Please sign in to comment.