Add support for rotated appendices: implement 90° CCW image rotation for portrait pages, enhance table rendering logic, and update diagram handling directives.
This commit is contained in:
+27
-3
@@ -46,6 +46,7 @@ func ParseMarkdown(mdPath string) (Config, ast.Node, []byte, error) {
|
||||
type parserState struct {
|
||||
nextCodeIsAppendix bool
|
||||
nextAppendixLandscape bool // set by @AnhangUMLQuer: — landscape for diagram appendix
|
||||
nextAppendixRotated bool // set by @AnhangUMLGedreht: — portrait page, image rotated 90° CCW
|
||||
appendixTitle string
|
||||
nextCodeBlockAppendix bool // set by @AnhangCode: — next non-diagram code block → appendix
|
||||
codeBlockAppendixTitle string
|
||||
@@ -122,6 +123,7 @@ func RenderAST(doc ast.Node, content []byte, r *IHKRenderer) error {
|
||||
state.nextDiagramCaption = ""
|
||||
state.nextCodeIsAppendix = false
|
||||
state.nextAppendixLandscape = false
|
||||
state.nextAppendixRotated = false
|
||||
}
|
||||
if err == nil {
|
||||
switch {
|
||||
@@ -130,15 +132,24 @@ func RenderAST(doc ast.Node, content []byte, r *IHKRenderer) error {
|
||||
state.nextDiagramLandscape = false
|
||||
state.nextDiagramCaption = ""
|
||||
case state.nextCodeIsAppendix:
|
||||
if state.nextAppendixLandscape {
|
||||
switch {
|
||||
case state.nextAppendixLandscape:
|
||||
r.AddLandscapeAppendix(state.appendixTitle + " | " + imgPath)
|
||||
state.nextAppendixLandscape = false
|
||||
} else {
|
||||
case state.nextAppendixRotated:
|
||||
r.AddRotatedUMLAppendix(state.appendixTitle, imgPath)
|
||||
state.nextAppendixRotated = false
|
||||
default:
|
||||
r.AddAppendix(state.appendixTitle + " | " + imgPath)
|
||||
}
|
||||
state.nextCodeIsAppendix = false
|
||||
default:
|
||||
r.RenderImage(imgPath, "Diagram ("+lang+")")
|
||||
caption := state.nextDiagramCaption
|
||||
if caption == "" {
|
||||
caption = "Diagram (" + lang + ")"
|
||||
}
|
||||
state.nextDiagramCaption = ""
|
||||
r.RenderImage(imgPath, caption)
|
||||
}
|
||||
return ast.WalkSkipChildren, nil
|
||||
}
|
||||
@@ -287,6 +298,15 @@ func handleDirectives(text string, state *parserState, r *IHKRenderer) bool {
|
||||
state.nextAppendixLandscape = true
|
||||
state.appendixTitle = strings.TrimSpace(strings.TrimPrefix(line, "@AnhangUMLQuer:"))
|
||||
handled = true
|
||||
case strings.HasPrefix(line, "@AnhangUMLGedreht:"):
|
||||
// Portrait page, image rotated 90° CCW — long axis runs top-to-bottom.
|
||||
state.nextCodeIsAppendix = true
|
||||
state.nextAppendixRotated = true
|
||||
state.appendixTitle = strings.TrimSpace(strings.TrimPrefix(line, "@AnhangUMLGedreht:"))
|
||||
handled = true
|
||||
case strings.HasPrefix(line, "@AnhangBildGedreht:"):
|
||||
r.AddRotatedImageAppendix(strings.TrimSpace(strings.TrimPrefix(line, "@AnhangBildGedreht:")))
|
||||
handled = true
|
||||
case strings.HasPrefix(line, "@AnhangUML:"):
|
||||
state.nextCodeIsAppendix = true
|
||||
state.appendixTitle = strings.TrimSpace(strings.TrimPrefix(line, "@AnhangUML:"))
|
||||
@@ -307,6 +327,10 @@ func handleDirectives(text string, state *parserState, r *IHKRenderer) bool {
|
||||
state.nextDiagramLandscape = true
|
||||
state.nextDiagramCaption = strings.TrimSpace(strings.TrimPrefix(line, "@DiagrammQuer:"))
|
||||
handled = true
|
||||
case strings.HasPrefix(line, "@Diagramm:"):
|
||||
// Portrait inline diagram — rendered at current position via RenderImage.
|
||||
state.nextDiagramCaption = strings.TrimSpace(strings.TrimPrefix(line, "@Diagramm:"))
|
||||
handled = true
|
||||
}
|
||||
}
|
||||
return handled
|
||||
|
||||
Reference in New Issue
Block a user