Closed xiebruce closed 1 year ago
If I understand you correctly, you want that
<text-style ref="ts3">Default Title</text-style>
be kept on the same line while the other tags separated in different lines as of now, right?
If I understand you correctly, you want that
<text-style ref="ts3">Default Title</text-style>
be kept on the same line while the other tags separated in different lines as of now, right?
Yes!
it should be this
<text-style ref="ts2">Default Title</text-style>
not this(which is currently happening):
<text-style ref="ts2">Default Title
</text-style>
Do you have an idea how to do that?
The way I view it -- it is what it is, i.e., you can't have some random tags on the same line while others don't. A program logic doesn't work that way.
It is not 100% impossible, but I'm reluctant to put in my effort on something I view as useless. If this is so important to you, hope that it can give you enough incentive to scratch your own itches, and send in PR hopefully. (however, if the solution is not elegant enough, or it is taking too much percentage of code (say 2%), I might not take it in to maintain it).
The other option you have is, since your xml is only of version 1, with no name spaces, you can just go through the decoding and encoding procedures. But I doubt that the standard output will give what you want either.
It is not 100% impossible...
In other words, I view the implementation would be messy and bulky, just to solve such a trivial thing.
But feel free to enlighten me.
you can't have some random tags on the same line while others don't.
Yes, I agree, maybe just leave it, for now I'm replacing the \n
and spaces(\s
) using RegExp
r_inside_whitespace := regexp.MustCompile(`[\s\p{Zs}]+(</text-style>)`)
xml = r_inside_whitespace.ReplaceAllString(xml, "$1")
I prefer this:
// end elem
if strings.HasPrefix(m, "</") {
indentLevel--
return m
}
But the previous elem did not wrap,like this:
<MZBRCF>
<CFID>6083</CFID></MZBRCF>
<MZBRCF>
<CFID>6084</CFID>
...
So I changed it:
func replaceTag(prefix, indent string) func(string) string {
indentLevel := 0
lastEndElem := true
return func(m string) string {
...
// end elem
if strings.HasPrefix(m, "</") {
indentLevel--
if lastEndElem {
return NL + prefix + strings.Repeat(indent, indentLevel) + m
}
lastEndElem = true
return m
} else {
lastEndElem = false
}
defer func() {
indentLevel++
}()
return NL + prefix + strings.Repeat(indent, indentLevel) + m
}
}
So I changed it:
<?xml version="1.0" encoding="UTF-8"?>
<MZBRCFS>
<MZBRCF>
<CFID>6078</CFID>
</MZBRCF>
<MZBRCF>
<CFID>6079</CFID>
</MZBRCF>
</MZBRCFS>
Hmm, thanks.
Would you send a PR please? which should include the following two/three steps,
Thanks & looking forward to your PR.
Okay, I'm testing it.
yeah, that extra space at the end, I think you've got it. :+1:
LMK otherwise.
xmlfmt.FormatXML()
auto adds a\n
before</text-style>
Here is the contents of
example.fcpxml
, there's no\n
before</text-style>