">" causes some issue when running "build"
ubukawa opened this issue · comments
Describe the bug
If the "id" of any layer in "layers" is long, ">" 「折り返し形式のブロックスカラー」 is used in the layer list during the import, and it causes problem when we build JSON from YAML.
To Reproduce
Steps to reproduce the behavior:
- Prepare a style json with a long layer name.
- Import that JSON file into YAML.
- Confirm that ">" is used together with "!!inc/file."
- Build a newe JSON form imported YAML file.
- Then, you will see an error that says "Cannot use 'in' operator to search for 'ref' in !!inc/fil ...."
Expected behavior
Build can be successfully done.
Screenshots
If applicable, add screenshots to help explain your problem.
Charites Version:
- Charites version: keichan34/charites:upport-slash-in-layer-id https://github.com/keichan34/charites/tree/support-slash-in-layer-id
Desktop (please complete the following information):
- OS: [e.g. Windows] Windows/Docker (unvt/nanban)
- Browser [e.g. chrome, safari]
- Version [e.g. 22]
Additional context
Add any other context about the problem here.
OK, I think I know why this isn't being parsed correctly.
!!inc/file
is a YAML tag? type? statement, and is probably not parsed as such when using a multiline statement such as >-
(I found this when looking up multiline statements... 👀 )
As a solution, I think maybe setting lineWidth: -1
for unlimited width when running YAML.dump
would work? I don't necessarily like this solution...
Maybe as an alternative we can try removing the replace here:
charites/src/lib/yaml-writer.ts
Lines 65 to 70 in 3a6b5ec
and replacing it with a non-string type that directly translates to
!!inc/file
when running YAML.dump?
charites/src/lib/yaml-writer.ts
Lines 55 to 58 in 3a6b5ec
Looking at yaml-include, it doesn't look like we can use that, so we could possibly make a temporary schema just for this:
class IncFileTag {
constructor(fileName) {
this.value = path.posix.join('layers', fileName)
}
}
const incFileYamlType = new yaml.Type('!!inc/file', { kind: 'scalar', resolve: data => data, construct, data => new IncFileTag(data), instanceOf: IncFileTag, represent: tag => tag.value })
const schema = yaml.Schema.create([incFileYamlType])
...
layers.push(new IncFileTag(fileName))
...
yaml.dump(style, { schema: schema })
(I haven't tested it yet... I'll try to get around to trying to fix this in the near future if nobody else wants to.. 🙂 )
Thank you very much for your consideration. Although I cannot immediately understand your script, I keep watching this!
This is the issue, I have written here.
https://unvt.github.io/charites/usage/example2.html#step-2-checking-an-overall-yaml-style-yml-in-this-case
">-" is good if it appears in "attribution" and others, but not in "layers."