@@ -15,6 +15,7 @@ import { formatResourcePath } from "../resources.ts";
1515import { join } from "path/mod.ts" ;
1616import {
1717 isJavascriptCompatible ,
18+ isLatexOutput ,
1819 isMarkdownOutput ,
1920 isRevealjsOutput ,
2021} from "../../config/format.ts" ;
@@ -36,6 +37,7 @@ import {
3637import { Element } from "../deno-dom.ts" ;
3738import { convertFromYaml } from "../lib/yaml-schema/from-yaml.ts" ;
3839import { readYamlFromString } from "../yaml.ts" ;
40+ import { LocalizedError } from "../lib/error.ts" ;
3941
4042const mermaidHandler : LanguageHandler = {
4143 ...baseHandler ,
@@ -139,14 +141,22 @@ object:
139141 } ) ;
140142 }
141143
142- return this . build (
143- handlerContext ,
144- cell ,
145- svg ,
146- options ,
147- undefined ,
148- new Set ( [ "fig-width" , "fig-height" ] ) ,
149- ) ;
144+ if ( isMarkdownOutput ( handlerContext . options . format . pandoc , [ "gfm" ] ) ) {
145+ throw new LocalizedError (
146+ "UnsupportedFormatError" ,
147+ "`mermaid-format: svg` is not supported in GFM format" ,
148+ cell . sourceVerbatim ,
149+ ) ;
150+ } else {
151+ return this . build (
152+ handlerContext ,
153+ cell ,
154+ svg ,
155+ options ,
156+ undefined ,
157+ new Set ( [ "fig-width" , "fig-height" ] ) ,
158+ ) ;
159+ }
150160 } ;
151161
152162 const makePng = async ( ) => {
@@ -162,21 +172,36 @@ object:
162172 resources,
163173 } ) ;
164174
165- const {
175+ let {
166176 widthInInches,
167177 heightInInches,
168178 } = await resolveSize ( svgText , options ) ;
169-
170- return this . build (
171- handlerContext ,
172- cell ,
173- mappedConcat ( [
174- `\n{width="${ widthInInches } in" height="${ heightInInches } in" fig-pos='H'}\n` ,
175- ] ) ,
176- options ,
177- undefined ,
178- new Set ( [ "fig-width" , "fig-height" ] ) ,
179- ) ;
179+ widthInInches = Math . round ( widthInInches * 100 ) / 100 ;
180+ heightInInches = Math . round ( heightInInches * 100 ) / 100 ;
181+
182+ const posSpecifier = isLatexOutput ( handlerContext . options . format . pandoc )
183+ ? " fig-pos='H'"
184+ : "" ;
185+ const idSpecifier = cell . options ?. label ? ` #${ cell . options ?. label } ` : "" ;
186+
187+ const cellContent = mappedConcat ( [
188+ `\n![${
189+ cell . options ?. [ "fig-cap" ] || ""
190+ } ](${ sourceName } ){width="${ widthInInches } in" height="${ heightInInches } in"${ posSpecifier } ${ idSpecifier } }\n`,
191+ ] ) ;
192+
193+ if ( isMarkdownOutput ( handlerContext . options . format . pandoc , [ "gfm" ] ) ) {
194+ return cellContent ;
195+ } else {
196+ return this . build (
197+ handlerContext ,
198+ cell ,
199+ cellContent ,
200+ options ,
201+ undefined ,
202+ new Set ( [ "fig-width" , "fig-height" ] ) ,
203+ ) ;
204+ }
180205 } ;
181206
182207 const makeDefault = async ( ) => {
@@ -185,14 +210,15 @@ object:
185210 } else if (
186211 isMarkdownOutput ( handlerContext . options . format . pandoc , [ "gfm" ] )
187212 ) {
188- return this . build (
213+ return mappedConcat ( [ "\n``` mermaid\n" , cellContent , "\n```\n" ] ) ;
214+
215+ /*return this.build(
189216 handlerContext,
190217 cell,
191- mappedConcat ( [ "\n``` mermaid\n" , cellContent , "\n```\n" ] ) ,
192218 options,
193219 undefined,
194220 new Set(["fig-width", "fig-height"]),
195- ) ;
221+ );*/
196222 } else {
197223 return await makePng ( ) ;
198224 }
0 commit comments