d2cli: no-xml-tag
This commit is contained in:
parent
1999f8052d
commit
83b96c2734
3 changed files with 34 additions and 1 deletions
|
|
@ -129,6 +129,11 @@ func Run(ctx context.Context, ms *xmain.State) (err error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
noXMLTagFlag, err := ms.Opts.Bool("D2_NO_XML_TAG", "no-xml-tag", "", false, "suppress the XML declaration in SVG output")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
plugins, err := d2plugin.ListPlugins(ctx)
|
plugins, err := d2plugin.ListPlugins(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -318,6 +323,7 @@ func Run(ctx context.Context, ms *xmain.State) (err error) {
|
||||||
ThemeID: themeFlag,
|
ThemeID: themeFlag,
|
||||||
DarkThemeID: darkThemeFlag,
|
DarkThemeID: darkThemeFlag,
|
||||||
Scale: scale,
|
Scale: scale,
|
||||||
|
NoXMLTag: noXMLTagFlag,
|
||||||
}
|
}
|
||||||
|
|
||||||
if *watchFlag {
|
if *watchFlag {
|
||||||
|
|
@ -868,6 +874,7 @@ func _render(ctx context.Context, ms *xmain.State, plugin d2plugin.Plugin, opts
|
||||||
DarkThemeID: opts.DarkThemeID,
|
DarkThemeID: opts.DarkThemeID,
|
||||||
ThemeOverrides: opts.ThemeOverrides,
|
ThemeOverrides: opts.ThemeOverrides,
|
||||||
DarkThemeOverrides: opts.DarkThemeOverrides,
|
DarkThemeOverrides: opts.DarkThemeOverrides,
|
||||||
|
NoXMLTag: opts.NoXMLTag,
|
||||||
Scale: scale,
|
Scale: scale,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -86,6 +86,7 @@ type RenderOpts struct {
|
||||||
// MasterID is passed when the diagram should use something other than its own hash for unique targeting
|
// MasterID is passed when the diagram should use something other than its own hash for unique targeting
|
||||||
// Currently, that's when multi-boards are collapsed
|
// Currently, that's when multi-boards are collapsed
|
||||||
MasterID string
|
MasterID string
|
||||||
|
NoXMLTag *bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func dimensions(diagram *d2target.Diagram, pad int) (left, top, width, height int) {
|
func dimensions(diagram *d2target.Diagram, pad int) (left, top, width, height int) {
|
||||||
|
|
@ -2117,7 +2118,9 @@ func Render(diagram *d2target.Diagram, opts *RenderOpts) ([]byte, error) {
|
||||||
w, h,
|
w, h,
|
||||||
dimensions,
|
dimensions,
|
||||||
)
|
)
|
||||||
xmlTag = `<?xml version="1.0" encoding="utf-8"?>`
|
if opts.NoXMLTag == nil || !*opts.NoXMLTag {
|
||||||
|
xmlTag = `<?xml version="1.0" encoding="utf-8"?>`
|
||||||
|
}
|
||||||
fitToScreenWrapperClosing = "</svg>"
|
fitToScreenWrapperClosing = "</svg>"
|
||||||
idAttr = `id="d2-svg"`
|
idAttr = `id="d2-svg"`
|
||||||
tag = "svg"
|
tag = "svg"
|
||||||
|
|
|
||||||
|
|
@ -982,6 +982,29 @@ layers: {
|
||||||
testdataIgnoreDiff(t, ".pptx", file)
|
testdataIgnoreDiff(t, ".pptx", file)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "no_xml_tag",
|
||||||
|
run: func(t *testing.T, ctx context.Context, dir string, env *xos.Env) {
|
||||||
|
writeFile(t, dir, "test.d2", `x -> y`)
|
||||||
|
err := runTestMain(t, ctx, dir, env, "--no-xml-tag", "test.d2", "no-xml.svg")
|
||||||
|
assert.Success(t, err)
|
||||||
|
noXMLSvg := readFile(t, dir, "no-xml.svg")
|
||||||
|
assert.False(t, strings.Contains(string(noXMLSvg), "<?xml"))
|
||||||
|
|
||||||
|
writeFile(t, dir, "test.d2", `x -> y`)
|
||||||
|
err = runTestMain(t, ctx, dir, env, "test.d2", "with-xml.svg")
|
||||||
|
assert.Success(t, err)
|
||||||
|
withXMLSvg := readFile(t, dir, "with-xml.svg")
|
||||||
|
assert.True(t, strings.Contains(string(withXMLSvg), "<?xml"))
|
||||||
|
|
||||||
|
env.Setenv("D2_NO_XML_TAG", "1")
|
||||||
|
writeFile(t, dir, "test.d2", `x -> y`)
|
||||||
|
err = runTestMain(t, ctx, dir, env, "test.d2", "no-xml-env.svg")
|
||||||
|
assert.Success(t, err)
|
||||||
|
noXMLEnvSvg := readFile(t, dir, "no-xml-env.svg")
|
||||||
|
assert.False(t, strings.Contains(string(noXMLEnvSvg), "<?xml"))
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "basic-fmt",
|
name: "basic-fmt",
|
||||||
run: func(t *testing.T, ctx context.Context, dir string, env *xos.Env) {
|
run: func(t *testing.T, ctx context.Context, dir string, env *xos.Env) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue