| 1 |
|
| 2 |
package parser |
| 3 |
|
| 4 |
import ( |
| 5 |
"fmt" |
| 6 |
"strings" |
| 7 |
"sync" |
| 8 |
|
| 9 |
"github.com/yuin/goldmark/ast" |
| 10 |
"github.com/yuin/goldmark/text" |
| 11 |
"github.com/yuin/goldmark/util" |
| 12 |
) |
| 13 |
|
| 14 |
|
| 15 |
type Reference interface { |
| 16 |
|
| 17 |
String() string |
| 18 |
|
| 19 |
|
| 20 |
Label() []byte |
| 21 |
|
| 22 |
|
| 23 |
Destination() []byte |
| 24 |
|
| 25 |
|
| 26 |
Title() []byte |
| 27 |
} |
| 28 |
|
| 29 |
type reference struct { |
| 30 |
label []byte |
| 31 |
destination []byte |
| 32 |
title []byte |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
func NewReference(label, destination, title []byte) Reference { |
| 37 |
return &reference{label, destination, title} |
| 38 |
} |
| 39 |
|
| 40 |
func newASTReference(v *ast.LinkReferenceDefinition) Reference { |
| 41 |
return &astReference{v} |
| 42 |
} |
| 43 |
|
| 44 |
func (r *reference) Label() []byte { |
| 45 |
return r.label |
| 46 |
} |
| 47 |
|
| 48 |
func (r *reference) Destination() []byte { |
| 49 |
return r.destination |
| 50 |
} |
| 51 |
|
| 52 |
func (r *reference) Title() []byte { |
| 53 |
return r.title |
| 54 |
} |
| 55 |
|
| 56 |
func (r *reference) String() string { |
| 57 |
return fmt.Sprintf("Reference{Label:%s, Destination:%s, Title:%s}", r.label, r.destination, r.title) |
| 58 |
} |
| 59 |
|
| 60 |
type astReference struct { |
| 61 |
v *ast.LinkReferenceDefinition |
| 62 |
} |
| 63 |
|
| 64 |
func (r *astReference) Label() []byte { |
| 65 |
return r.v.Label |
| 66 |
} |
| 67 |
|
| 68 |
func (r *astReference) Destination() []byte { |
| 69 |
return r.v.Destination |
| 70 |
} |
| 71 |
|
| 72 |
func (r *astReference) Title() []byte { |
| 73 |
return r.v.Title |
| 74 |
} |
| 75 |
|
| 76 |
func (r *astReference) String() string { |
| 77 |
return fmt.Sprintf("Reference{Label:%s, Destination:%s, Title:%s}", r.Label(), r.Destination(), r.Title()) |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
type IDs interface { |
| 82 |
|
| 83 |
Generate(value []byte, kind ast.NodeKind) []byte |
| 84 |
|
| 85 |
|
| 86 |
Put(value []byte) |
| 87 |
} |
| 88 |
|
| 89 |
type ids struct { |
| 90 |
values map[string]bool |
| 91 |
} |
| 92 |
|
| 93 |
func newIDs() IDs { |
| 94 |
return &ids{ |
| 95 |
values: map[string]bool{}, |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
func (s *ids) Generate(value []byte, kind ast.NodeKind) []byte { |
| 100 |
value = util.TrimLeftSpace(value) |
| 101 |
value = util.TrimRightSpace(value) |
| 102 |
result := []byte{} |
| 103 |
for i := 0; i < len(value); { |
| 104 |
v := value[i] |
| 105 |
l := util.UTF8Len(v) |
| 106 |
i += int(l) |
| 107 |
if l != 1 { |
| 108 |
continue |
| 109 |
} |
| 110 |
if util.IsAlphaNumeric(v) { |
| 111 |
if 'A' <= v && v <= 'Z' { |
| 112 |
v += 'a' - 'A' |
| 113 |
} |
| 114 |
result = append(result, v) |
| 115 |
} else if util.IsSpace(v) || v == '-' || v == '_' { |
| 116 |
result = append(result, '-') |
| 117 |
} |
| 118 |
} |
| 119 |
if len(result) == 0 { |
| 120 |
if kind == ast.KindHeading { |
| 121 |
result = []byte("heading") |
| 122 |
} else { |
| 123 |
result = []byte("id") |
| 124 |
} |
| 125 |
} |
| 126 |
if _, ok := s.values[util.BytesToReadOnlyString(result)]; !ok { |
| 127 |
s.values[util.BytesToReadOnlyString(result)] = true |
| 128 |
return result |
| 129 |
} |
| 130 |
for i := 1; ; i++ { |
| 131 |
newResult := fmt.Sprintf("%s-%d", result, i) |
| 132 |
if _, ok := s.values[newResult]; !ok { |
| 133 |
s.values[newResult] = true |
| 134 |
return []byte(newResult) |
| 135 |
} |
| 136 |
|
| 137 |
} |
| 138 |
} |
| 139 |
|
| 140 |
func (s *ids) Put(value []byte) { |
| 141 |
s.values[util.BytesToReadOnlyString(value)] = true |
| 142 |
} |
| 143 |
|
| 144 |
|
| 145 |
type ContextKey int |
| 146 |
|
| 147 |
|
| 148 |
var ContextKeyMax ContextKey |
| 149 |
|
| 150 |
|
| 151 |
func NewContextKey() ContextKey { |
| 152 |
ContextKeyMax++ |
| 153 |
return ContextKeyMax |
| 154 |
} |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
type Context interface { |
| 159 |
|
| 160 |
String() string |
| 161 |
|
| 162 |
|
| 163 |
Get(ContextKey) any |
| 164 |
|
| 165 |
|
| 166 |
ComputeIfAbsent(ContextKey, func() any) any |
| 167 |
|
| 168 |
|
| 169 |
Set(ContextKey, any) |
| 170 |
|
| 171 |
|
| 172 |
AddReference(Reference) |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
Reference(label string) (Reference, bool) |
| 177 |
|
| 178 |
|
| 179 |
References() []Reference |
| 180 |
|
| 181 |
|
| 182 |
IDs() IDs |
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
BlockOffset() int |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
SetBlockOffset(int) |
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
BlockIndent() int |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
SetBlockIndent(int) |
| 201 |
|
| 202 |
|
| 203 |
FirstDelimiter() *Delimiter |
| 204 |
|
| 205 |
|
| 206 |
LastDelimiter() *Delimiter |
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
PushDelimiter(delimiter *Delimiter) |
| 211 |
|
| 212 |
|
| 213 |
RemoveDelimiter(d *Delimiter) |
| 214 |
|
| 215 |
|
| 216 |
ClearDelimiters(bottom ast.Node) |
| 217 |
|
| 218 |
|
| 219 |
OpenedBlocks() []Block |
| 220 |
|
| 221 |
|
| 222 |
SetOpenedBlocks([]Block) |
| 223 |
|
| 224 |
|
| 225 |
LastOpenedBlock() Block |
| 226 |
|
| 227 |
|
| 228 |
IsInLinkLabel() bool |
| 229 |
} |
| 230 |
|
| 231 |
|
| 232 |
type ContextConfig struct { |
| 233 |
IDs IDs |
| 234 |
} |
| 235 |
|
| 236 |
|
| 237 |
type ContextOption func(*ContextConfig) |
| 238 |
|
| 239 |
|
| 240 |
func WithIDs(ids IDs) ContextOption { |
| 241 |
return func(c *ContextConfig) { |
| 242 |
c.IDs = ids |
| 243 |
} |
| 244 |
} |
| 245 |
|
| 246 |
type parseContext struct { |
| 247 |
store []any |
| 248 |
ids IDs |
| 249 |
refs map[string]Reference |
| 250 |
blockOffset int |
| 251 |
blockIndent int |
| 252 |
delimiters *Delimiter |
| 253 |
lastDelimiter *Delimiter |
| 254 |
openedBlocks []Block |
| 255 |
} |
| 256 |
|
| 257 |
|
| 258 |
func NewContext(options ...ContextOption) Context { |
| 259 |
cfg := &ContextConfig{ |
| 260 |
IDs: newIDs(), |
| 261 |
} |
| 262 |
for _, option := range options { |
| 263 |
option(cfg) |
| 264 |
} |
| 265 |
|
| 266 |
return &parseContext{ |
| 267 |
store: make([]any, ContextKeyMax+1), |
| 268 |
refs: map[string]Reference{}, |
| 269 |
ids: cfg.IDs, |
| 270 |
blockOffset: -1, |
| 271 |
blockIndent: -1, |
| 272 |
delimiters: nil, |
| 273 |
lastDelimiter: nil, |
| 274 |
openedBlocks: []Block{}, |
| 275 |
} |
| 276 |
} |
| 277 |
|
| 278 |
func (p *parseContext) Get(key ContextKey) any { |
| 279 |
return p.store[key] |
| 280 |
} |
| 281 |
|
| 282 |
func (p *parseContext) ComputeIfAbsent(key ContextKey, f func() any) any { |
| 283 |
v := p.store[key] |
| 284 |
if v == nil { |
| 285 |
v = f() |
| 286 |
p.store[key] = v |
| 287 |
} |
| 288 |
return v |
| 289 |
} |
| 290 |
|
| 291 |
func (p *parseContext) Set(key ContextKey, value any) { |
| 292 |
p.store[key] = value |
| 293 |
} |
| 294 |
|
| 295 |
func (p *parseContext) IDs() IDs { |
| 296 |
return p.ids |
| 297 |
} |
| 298 |
|
| 299 |
func (p *parseContext) BlockOffset() int { |
| 300 |
return p.blockOffset |
| 301 |
} |
| 302 |
|
| 303 |
func (p *parseContext) SetBlockOffset(v int) { |
| 304 |
p.blockOffset = v |
| 305 |
} |
| 306 |
|
| 307 |
func (p *parseContext) BlockIndent() int { |
| 308 |
return p.blockIndent |
| 309 |
} |
| 310 |
|
| 311 |
func (p *parseContext) SetBlockIndent(v int) { |
| 312 |
p.blockIndent = v |
| 313 |
} |
| 314 |
|
| 315 |
func (p *parseContext) LastDelimiter() *Delimiter { |
| 316 |
return p.lastDelimiter |
| 317 |
} |
| 318 |
|
| 319 |
func (p *parseContext) FirstDelimiter() *Delimiter { |
| 320 |
return p.delimiters |
| 321 |
} |
| 322 |
|
| 323 |
func (p *parseContext) PushDelimiter(d *Delimiter) { |
| 324 |
if p.delimiters == nil { |
| 325 |
p.delimiters = d |
| 326 |
p.lastDelimiter = d |
| 327 |
} else { |
| 328 |
l := p.lastDelimiter |
| 329 |
p.lastDelimiter = d |
| 330 |
l.NextDelimiter = d |
| 331 |
d.PreviousDelimiter = l |
| 332 |
} |
| 333 |
} |
| 334 |
|
| 335 |
func (p *parseContext) RemoveDelimiter(d *Delimiter) { |
| 336 |
if d.PreviousDelimiter == nil { |
| 337 |
p.delimiters = d.NextDelimiter |
| 338 |
} else { |
| 339 |
d.PreviousDelimiter.NextDelimiter = d.NextDelimiter |
| 340 |
if d.NextDelimiter != nil { |
| 341 |
d.NextDelimiter.PreviousDelimiter = d.PreviousDelimiter |
| 342 |
} |
| 343 |
} |
| 344 |
if d.NextDelimiter == nil { |
| 345 |
p.lastDelimiter = d.PreviousDelimiter |
| 346 |
} |
| 347 |
if p.delimiters != nil { |
| 348 |
p.delimiters.PreviousDelimiter = nil |
| 349 |
} |
| 350 |
if p.lastDelimiter != nil { |
| 351 |
p.lastDelimiter.NextDelimiter = nil |
| 352 |
} |
| 353 |
d.NextDelimiter = nil |
| 354 |
d.PreviousDelimiter = nil |
| 355 |
if d.Length != 0 { |
| 356 |
ast.MergeOrReplaceTextSegment(d.Parent(), d, d.Segment) |
| 357 |
} else { |
| 358 |
d.Parent().RemoveChild(d.Parent(), d) |
| 359 |
} |
| 360 |
} |
| 361 |
|
| 362 |
func (p *parseContext) ClearDelimiters(bottom ast.Node) { |
| 363 |
if p.lastDelimiter == nil { |
| 364 |
return |
| 365 |
} |
| 366 |
var c ast.Node |
| 367 |
for c = p.lastDelimiter; c != nil && c != bottom; { |
| 368 |
prev := c.PreviousSibling() |
| 369 |
if d, ok := c.(*Delimiter); ok { |
| 370 |
p.RemoveDelimiter(d) |
| 371 |
} |
| 372 |
c = prev |
| 373 |
} |
| 374 |
} |
| 375 |
|
| 376 |
func (p *parseContext) AddReference(ref Reference) { |
| 377 |
key := util.ToLinkReference(ref.Label()) |
| 378 |
if _, ok := p.refs[key]; !ok { |
| 379 |
p.refs[key] = ref |
| 380 |
} |
| 381 |
} |
| 382 |
|
| 383 |
func (p *parseContext) Reference(label string) (Reference, bool) { |
| 384 |
v, ok := p.refs[label] |
| 385 |
return v, ok |
| 386 |
} |
| 387 |
|
| 388 |
func (p *parseContext) References() []Reference { |
| 389 |
ret := make([]Reference, 0, len(p.refs)) |
| 390 |
for _, v := range p.refs { |
| 391 |
ret = append(ret, v) |
| 392 |
} |
| 393 |
return ret |
| 394 |
} |
| 395 |
|
| 396 |
func (p *parseContext) String() string { |
| 397 |
refs := []string{} |
| 398 |
for _, r := range p.refs { |
| 399 |
refs = append(refs, r.String()) |
| 400 |
} |
| 401 |
|
| 402 |
return fmt.Sprintf("Context{Store:%#v, Refs:%s}", p.store, strings.Join(refs, ",")) |
| 403 |
} |
| 404 |
|
| 405 |
func (p *parseContext) OpenedBlocks() []Block { |
| 406 |
return p.openedBlocks |
| 407 |
} |
| 408 |
|
| 409 |
func (p *parseContext) SetOpenedBlocks(v []Block) { |
| 410 |
p.openedBlocks = v |
| 411 |
} |
| 412 |
|
| 413 |
func (p *parseContext) LastOpenedBlock() Block { |
| 414 |
if l := len(p.openedBlocks); l != 0 { |
| 415 |
return p.openedBlocks[l-1] |
| 416 |
} |
| 417 |
return Block{} |
| 418 |
} |
| 419 |
|
| 420 |
func (p *parseContext) IsInLinkLabel() bool { |
| 421 |
tlist := p.Get(linkLabelStateKey) |
| 422 |
return tlist != nil |
| 423 |
} |
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
type State int |
| 428 |
|
| 429 |
const ( |
| 430 |
|
| 431 |
None State = 1 << iota |
| 432 |
|
| 433 |
|
| 434 |
Continue |
| 435 |
|
| 436 |
|
| 437 |
Close |
| 438 |
|
| 439 |
|
| 440 |
HasChildren |
| 441 |
|
| 442 |
|
| 443 |
NoChildren |
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
RequireParagraph |
| 449 |
) |
| 450 |
|
| 451 |
|
| 452 |
type Config struct { |
| 453 |
Options map[OptionName]any |
| 454 |
BlockParsers util.PrioritizedSlice |
| 455 |
InlineParsers util.PrioritizedSlice |
| 456 |
ParagraphTransformers util.PrioritizedSlice |
| 457 |
ASTTransformers util.PrioritizedSlice |
| 458 |
EscapedSpace bool |
| 459 |
} |
| 460 |
|
| 461 |
|
| 462 |
func NewConfig() *Config { |
| 463 |
return &Config{ |
| 464 |
Options: map[OptionName]any{}, |
| 465 |
BlockParsers: util.PrioritizedSlice{}, |
| 466 |
InlineParsers: util.PrioritizedSlice{}, |
| 467 |
ParagraphTransformers: util.PrioritizedSlice{}, |
| 468 |
ASTTransformers: util.PrioritizedSlice{}, |
| 469 |
} |
| 470 |
} |
| 471 |
|
| 472 |
|
| 473 |
type Option interface { |
| 474 |
SetParserOption(*Config) |
| 475 |
} |
| 476 |
|
| 477 |
|
| 478 |
type OptionName string |
| 479 |
|
| 480 |
|
| 481 |
const optAttribute OptionName = "Attribute" |
| 482 |
|
| 483 |
type withAttribute struct { |
| 484 |
} |
| 485 |
|
| 486 |
func (o *withAttribute) SetParserOption(c *Config) { |
| 487 |
c.Options[optAttribute] = true |
| 488 |
} |
| 489 |
|
| 490 |
|
| 491 |
func WithAttribute() Option { |
| 492 |
return &withAttribute{} |
| 493 |
} |
| 494 |
|
| 495 |
|
| 496 |
type Parser interface { |
| 497 |
|
| 498 |
Parse(reader text.Reader, opts ...ParseOption) ast.Node |
| 499 |
|
| 500 |
|
| 501 |
AddOptions(...Option) |
| 502 |
} |
| 503 |
|
| 504 |
|
| 505 |
type SetOptioner interface { |
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
SetOption(name OptionName, value any) |
| 510 |
} |
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
type BlockParser interface { |
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
Trigger() []byte |
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
Open(parent ast.Node, reader text.Reader, pc Context) (ast.Node, State) |
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
Continue(node ast.Node, reader text.Reader, pc Context) State |
| 542 |
|
| 543 |
|
| 544 |
Close(node ast.Node, reader text.Reader, pc Context) |
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
CanInterruptParagraph() bool |
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
CanAcceptIndentedLine() bool |
| 553 |
} |
| 554 |
|
| 555 |
|
| 556 |
type InlineParser interface { |
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
Trigger() []byte |
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
Parse(parent ast.Node, block text.Reader, pc Context) ast.Node |
| 570 |
} |
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
type CloseBlocker interface { |
| 575 |
|
| 576 |
CloseBlock(parent ast.Node, block text.Reader, pc Context) |
| 577 |
} |
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
type ParagraphTransformer interface { |
| 582 |
|
| 583 |
Transform(node *ast.Paragraph, reader text.Reader, pc Context) |
| 584 |
} |
| 585 |
|
| 586 |
|
| 587 |
type ASTTransformer interface { |
| 588 |
|
| 589 |
Transform(node *ast.Document, reader text.Reader, pc Context) |
| 590 |
} |
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
func DefaultBlockParsers() []util.PrioritizedValue { |
| 606 |
return []util.PrioritizedValue{ |
| 607 |
util.Prioritized(NewSetextHeadingParser(), 100), |
| 608 |
util.Prioritized(NewThematicBreakParser(), 200), |
| 609 |
util.Prioritized(NewListParser(), 300), |
| 610 |
util.Prioritized(NewListItemParser(), 400), |
| 611 |
util.Prioritized(NewCodeBlockParser(), 500), |
| 612 |
util.Prioritized(NewATXHeadingParser(), 600), |
| 613 |
util.Prioritized(NewFencedCodeBlockParser(), 700), |
| 614 |
util.Prioritized(NewBlockquoteParser(), 800), |
| 615 |
util.Prioritized(NewHTMLBlockParser(), 900), |
| 616 |
util.Prioritized(NewParagraphParser(), 1000), |
| 617 |
} |
| 618 |
} |
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
func DefaultInlineParsers() []util.PrioritizedValue { |
| 629 |
return []util.PrioritizedValue{ |
| 630 |
util.Prioritized(NewCodeSpanParser(), 100), |
| 631 |
util.Prioritized(NewLinkParser(), 200), |
| 632 |
util.Prioritized(NewAutoLinkParser(), 300), |
| 633 |
util.Prioritized(NewRawHTMLParser(), 400), |
| 634 |
util.Prioritized(NewEmphasisParser(), 500), |
| 635 |
} |
| 636 |
} |
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
func DefaultParagraphTransformers() []util.PrioritizedValue { |
| 643 |
return []util.PrioritizedValue{ |
| 644 |
util.Prioritized(LinkReferenceParagraphTransformer, 100), |
| 645 |
} |
| 646 |
} |
| 647 |
|
| 648 |
|
| 649 |
type Block struct { |
| 650 |
|
| 651 |
Node ast.Node |
| 652 |
|
| 653 |
Parser BlockParser |
| 654 |
} |
| 655 |
|
| 656 |
type parser struct { |
| 657 |
options map[OptionName]any |
| 658 |
blockParsers [256][]BlockParser |
| 659 |
freeBlockParsers []BlockParser |
| 660 |
inlineParsers [256][]InlineParser |
| 661 |
closeBlockers []CloseBlocker |
| 662 |
paragraphTransformers []ParagraphTransformer |
| 663 |
astTransformers []ASTTransformer |
| 664 |
escapedSpace bool |
| 665 |
config *Config |
| 666 |
initSync sync.Once |
| 667 |
} |
| 668 |
|
| 669 |
type withBlockParsers struct { |
| 670 |
value []util.PrioritizedValue |
| 671 |
} |
| 672 |
|
| 673 |
func (o *withBlockParsers) SetParserOption(c *Config) { |
| 674 |
c.BlockParsers = append(c.BlockParsers, o.value...) |
| 675 |
} |
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
func WithBlockParsers(bs ...util.PrioritizedValue) Option { |
| 680 |
return &withBlockParsers{bs} |
| 681 |
} |
| 682 |
|
| 683 |
type withInlineParsers struct { |
| 684 |
value []util.PrioritizedValue |
| 685 |
} |
| 686 |
|
| 687 |
func (o *withInlineParsers) SetParserOption(c *Config) { |
| 688 |
c.InlineParsers = append(c.InlineParsers, o.value...) |
| 689 |
} |
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
func WithInlineParsers(bs ...util.PrioritizedValue) Option { |
| 694 |
return &withInlineParsers{bs} |
| 695 |
} |
| 696 |
|
| 697 |
type withParagraphTransformers struct { |
| 698 |
value []util.PrioritizedValue |
| 699 |
} |
| 700 |
|
| 701 |
func (o *withParagraphTransformers) SetParserOption(c *Config) { |
| 702 |
c.ParagraphTransformers = append(c.ParagraphTransformers, o.value...) |
| 703 |
} |
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
func WithParagraphTransformers(ps ...util.PrioritizedValue) Option { |
| 708 |
return &withParagraphTransformers{ps} |
| 709 |
} |
| 710 |
|
| 711 |
type withASTTransformers struct { |
| 712 |
value []util.PrioritizedValue |
| 713 |
} |
| 714 |
|
| 715 |
func (o *withASTTransformers) SetParserOption(c *Config) { |
| 716 |
c.ASTTransformers = append(c.ASTTransformers, o.value...) |
| 717 |
} |
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
func WithASTTransformers(ps ...util.PrioritizedValue) Option { |
| 722 |
return &withASTTransformers{ps} |
| 723 |
} |
| 724 |
|
| 725 |
type withEscapedSpace struct { |
| 726 |
} |
| 727 |
|
| 728 |
func (o *withEscapedSpace) SetParserOption(c *Config) { |
| 729 |
c.EscapedSpace = true |
| 730 |
} |
| 731 |
|
| 732 |
|
| 733 |
func WithEscapedSpace() Option { |
| 734 |
return &withEscapedSpace{} |
| 735 |
} |
| 736 |
|
| 737 |
type withOption struct { |
| 738 |
name OptionName |
| 739 |
value any |
| 740 |
} |
| 741 |
|
| 742 |
func (o *withOption) SetParserOption(c *Config) { |
| 743 |
c.Options[o.name] = o.value |
| 744 |
} |
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
func WithOption(name OptionName, value any) Option { |
| 749 |
return &withOption{name, value} |
| 750 |
} |
| 751 |
|
| 752 |
|
| 753 |
func NewParser(options ...Option) Parser { |
| 754 |
config := NewConfig() |
| 755 |
for _, opt := range options { |
| 756 |
opt.SetParserOption(config) |
| 757 |
} |
| 758 |
|
| 759 |
p := &parser{ |
| 760 |
options: map[OptionName]any{}, |
| 761 |
config: config, |
| 762 |
} |
| 763 |
|
| 764 |
return p |
| 765 |
} |
| 766 |
|
| 767 |
func (p *parser) AddOptions(opts ...Option) { |
| 768 |
for _, opt := range opts { |
| 769 |
opt.SetParserOption(p.config) |
| 770 |
} |
| 771 |
} |
| 772 |
|
| 773 |
func (p *parser) addBlockParser(v util.PrioritizedValue, options map[OptionName]any) { |
| 774 |
bp, ok := v.Value.(BlockParser) |
| 775 |
if !ok { |
| 776 |
panic(fmt.Sprintf("%v is not a BlockParser", v.Value)) |
| 777 |
} |
| 778 |
tcs := bp.Trigger() |
| 779 |
so, ok := v.Value.(SetOptioner) |
| 780 |
if ok { |
| 781 |
for oname, ovalue := range options { |
| 782 |
so.SetOption(oname, ovalue) |
| 783 |
} |
| 784 |
} |
| 785 |
if tcs == nil { |
| 786 |
p.freeBlockParsers = append(p.freeBlockParsers, bp) |
| 787 |
} else { |
| 788 |
for _, tc := range tcs { |
| 789 |
if p.blockParsers[tc] == nil { |
| 790 |
p.blockParsers[tc] = []BlockParser{} |
| 791 |
} |
| 792 |
p.blockParsers[tc] = append(p.blockParsers[tc], bp) |
| 793 |
} |
| 794 |
} |
| 795 |
} |
| 796 |
|
| 797 |
func (p *parser) addInlineParser(v util.PrioritizedValue, options map[OptionName]any) { |
| 798 |
ip, ok := v.Value.(InlineParser) |
| 799 |
if !ok { |
| 800 |
panic(fmt.Sprintf("%v is not a InlineParser", v.Value)) |
| 801 |
} |
| 802 |
tcs := ip.Trigger() |
| 803 |
so, ok := v.Value.(SetOptioner) |
| 804 |
if ok { |
| 805 |
for oname, ovalue := range options { |
| 806 |
so.SetOption(oname, ovalue) |
| 807 |
} |
| 808 |
} |
| 809 |
if cb, ok := ip.(CloseBlocker); ok { |
| 810 |
p.closeBlockers = append(p.closeBlockers, cb) |
| 811 |
} |
| 812 |
for _, tc := range tcs { |
| 813 |
if p.inlineParsers[tc] == nil { |
| 814 |
p.inlineParsers[tc] = []InlineParser{} |
| 815 |
} |
| 816 |
p.inlineParsers[tc] = append(p.inlineParsers[tc], ip) |
| 817 |
} |
| 818 |
} |
| 819 |
|
| 820 |
func (p *parser) addParagraphTransformer(v util.PrioritizedValue, options map[OptionName]any) { |
| 821 |
pt, ok := v.Value.(ParagraphTransformer) |
| 822 |
if !ok { |
| 823 |
panic(fmt.Sprintf("%v is not a ParagraphTransformer", v.Value)) |
| 824 |
} |
| 825 |
so, ok := v.Value.(SetOptioner) |
| 826 |
if ok { |
| 827 |
for oname, ovalue := range options { |
| 828 |
so.SetOption(oname, ovalue) |
| 829 |
} |
| 830 |
} |
| 831 |
p.paragraphTransformers = append(p.paragraphTransformers, pt) |
| 832 |
} |
| 833 |
|
| 834 |
func (p *parser) addASTTransformer(v util.PrioritizedValue, options map[OptionName]any) { |
| 835 |
at, ok := v.Value.(ASTTransformer) |
| 836 |
if !ok { |
| 837 |
panic(fmt.Sprintf("%v is not a ASTTransformer", v.Value)) |
| 838 |
} |
| 839 |
so, ok := v.Value.(SetOptioner) |
| 840 |
if ok { |
| 841 |
for oname, ovalue := range options { |
| 842 |
so.SetOption(oname, ovalue) |
| 843 |
} |
| 844 |
} |
| 845 |
p.astTransformers = append(p.astTransformers, at) |
| 846 |
} |
| 847 |
|
| 848 |
|
| 849 |
type ParseConfig struct { |
| 850 |
Context Context |
| 851 |
} |
| 852 |
|
| 853 |
|
| 854 |
type ParseOption func(c *ParseConfig) |
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
func WithContext(context Context) ParseOption { |
| 859 |
return func(c *ParseConfig) { |
| 860 |
c.Context = context |
| 861 |
} |
| 862 |
} |
| 863 |
|
| 864 |
func (p *parser) Parse(reader text.Reader, opts ...ParseOption) ast.Node { |
| 865 |
p.initSync.Do(func() { |
| 866 |
p.config.BlockParsers.Sort() |
| 867 |
for _, v := range p.config.BlockParsers { |
| 868 |
p.addBlockParser(v, p.config.Options) |
| 869 |
} |
| 870 |
for i := range p.blockParsers { |
| 871 |
if p.blockParsers[i] != nil { |
| 872 |
p.blockParsers[i] = append(p.blockParsers[i], p.freeBlockParsers...) |
| 873 |
} |
| 874 |
} |
| 875 |
|
| 876 |
p.config.InlineParsers.Sort() |
| 877 |
for _, v := range p.config.InlineParsers { |
| 878 |
p.addInlineParser(v, p.config.Options) |
| 879 |
} |
| 880 |
p.config.ParagraphTransformers.Sort() |
| 881 |
for _, v := range p.config.ParagraphTransformers { |
| 882 |
p.addParagraphTransformer(v, p.config.Options) |
| 883 |
} |
| 884 |
p.config.ASTTransformers.Sort() |
| 885 |
for _, v := range p.config.ASTTransformers { |
| 886 |
p.addASTTransformer(v, p.config.Options) |
| 887 |
} |
| 888 |
p.escapedSpace = p.config.EscapedSpace |
| 889 |
p.config = nil |
| 890 |
}) |
| 891 |
c := &ParseConfig{} |
| 892 |
for _, opt := range opts { |
| 893 |
opt(c) |
| 894 |
} |
| 895 |
if c.Context == nil { |
| 896 |
c.Context = NewContext() |
| 897 |
} |
| 898 |
pc := c.Context |
| 899 |
root := ast.NewDocument() |
| 900 |
p.parseBlocks(root, reader, pc) |
| 901 |
|
| 902 |
blockReader := text.NewBlockReader(reader.Source(), nil) |
| 903 |
p.walkBlock(root, func(node ast.Node) { |
| 904 |
p.parseBlock(blockReader, node, pc) |
| 905 |
}) |
| 906 |
for _, at := range p.astTransformers { |
| 907 |
at.Transform(root, reader, pc) |
| 908 |
} |
| 909 |
|
| 910 |
|
| 911 |
return root |
| 912 |
} |
| 913 |
|
| 914 |
func (p *parser) transformParagraph(node *ast.Paragraph, reader text.Reader, pc Context) bool { |
| 915 |
for _, pt := range p.paragraphTransformers { |
| 916 |
pt.Transform(node, reader, pc) |
| 917 |
if node.Parent() == nil { |
| 918 |
return true |
| 919 |
} |
| 920 |
} |
| 921 |
return false |
| 922 |
} |
| 923 |
|
| 924 |
func (p *parser) closeBlocks(from, to int, reader text.Reader, pc Context) { |
| 925 |
blocks := pc.OpenedBlocks() |
| 926 |
for i := from; i >= to; i-- { |
| 927 |
node := blocks[i].Node |
| 928 |
paragraph, ok := node.(*ast.Paragraph) |
| 929 |
if ok && node.Parent() != nil { |
| 930 |
p.transformParagraph(paragraph, reader, pc) |
| 931 |
} |
| 932 |
if node.Parent() != nil { |
| 933 |
blocks[i].Parser.Close(blocks[i].Node, reader, pc) |
| 934 |
} |
| 935 |
} |
| 936 |
if from == len(blocks)-1 { |
| 937 |
blocks = blocks[0:to] |
| 938 |
} else { |
| 939 |
blocks = append(blocks[0:to], blocks[from+1:]...) |
| 940 |
} |
| 941 |
pc.SetOpenedBlocks(blocks) |
| 942 |
} |
| 943 |
|
| 944 |
type blockOpenResult int |
| 945 |
|
| 946 |
const ( |
| 947 |
paragraphContinuation blockOpenResult = iota + 1 |
| 948 |
newBlocksOpened |
| 949 |
noBlocksOpened |
| 950 |
) |
| 951 |
|
| 952 |
func (p *parser) openBlocks(parent ast.Node, blankLine bool, reader text.Reader, pc Context) blockOpenResult { |
| 953 |
result := blockOpenResult(noBlocksOpened) |
| 954 |
continuable := false |
| 955 |
lastBlock := pc.LastOpenedBlock() |
| 956 |
if lastBlock.Node != nil { |
| 957 |
continuable = ast.IsParagraph(lastBlock.Node) |
| 958 |
} |
| 959 |
retry: |
| 960 |
var bps []BlockParser |
| 961 |
line, _ := reader.PeekLine() |
| 962 |
w, pos := util.IndentWidth(line, reader.LineOffset()) |
| 963 |
if w >= len(line) { |
| 964 |
pc.SetBlockOffset(-1) |
| 965 |
pc.SetBlockIndent(-1) |
| 966 |
} else { |
| 967 |
pc.SetBlockOffset(pos) |
| 968 |
pc.SetBlockIndent(w) |
| 969 |
} |
| 970 |
if line == nil || line[0] == '\n' { |
| 971 |
goto continuable |
| 972 |
} |
| 973 |
bps = p.freeBlockParsers |
| 974 |
if pos < len(line) { |
| 975 |
bps = p.blockParsers[line[pos]] |
| 976 |
if bps == nil { |
| 977 |
bps = p.freeBlockParsers |
| 978 |
} |
| 979 |
} |
| 980 |
if bps == nil { |
| 981 |
goto continuable |
| 982 |
} |
| 983 |
|
| 984 |
for _, bp := range bps { |
| 985 |
if continuable && result == noBlocksOpened && !bp.CanInterruptParagraph() { |
| 986 |
continue |
| 987 |
} |
| 988 |
|
| 989 |
if w > 3 && !bp.CanAcceptIndentedLine() { |
| 990 |
continue |
| 991 |
} |
| 992 |
lastBlock = pc.LastOpenedBlock() |
| 993 |
last := lastBlock.Node |
| 994 |
_, blockPos := reader.Position() |
| 995 |
node, state := bp.Open(parent, reader, pc) |
| 996 |
if node != nil { |
| 997 |
node.SetPos(blockPos.Start + max(pc.BlockOffset(), 0)) |
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
if state&RequireParagraph != 0 { |
| 1013 |
if last == parent.LastChild() { |
| 1014 |
|
| 1015 |
|
| 1016 |
lastBlock.Parser.Close(last, reader, pc) |
| 1017 |
blocks := pc.OpenedBlocks() |
| 1018 |
pc.SetOpenedBlocks(blocks[0 : len(blocks)-1]) |
| 1019 |
if p.transformParagraph(last.(*ast.Paragraph), reader, pc) { |
| 1020 |
|
| 1021 |
|
| 1022 |
continuable = false |
| 1023 |
goto retry |
| 1024 |
} |
| 1025 |
} |
| 1026 |
} |
| 1027 |
node.SetBlankPreviousLines(blankLine) |
| 1028 |
if last != nil && last.Parent() == nil { |
| 1029 |
lastPos := len(pc.OpenedBlocks()) - 1 |
| 1030 |
p.closeBlocks(lastPos, lastPos, reader, pc) |
| 1031 |
} |
| 1032 |
parent.AppendChild(parent, node) |
| 1033 |
result = newBlocksOpened |
| 1034 |
be := Block{node, bp} |
| 1035 |
pc.SetOpenedBlocks(append(pc.OpenedBlocks(), be)) |
| 1036 |
if state&HasChildren != 0 { |
| 1037 |
parent = node |
| 1038 |
goto retry |
| 1039 |
} |
| 1040 |
break |
| 1041 |
} |
| 1042 |
} |
| 1043 |
|
| 1044 |
continuable: |
| 1045 |
if result == noBlocksOpened && continuable { |
| 1046 |
state := lastBlock.Parser.Continue(lastBlock.Node, reader, pc) |
| 1047 |
if state&Continue != 0 { |
| 1048 |
result = paragraphContinuation |
| 1049 |
} |
| 1050 |
} |
| 1051 |
return result |
| 1052 |
} |
| 1053 |
|
| 1054 |
type lineStat struct { |
| 1055 |
lineNum int |
| 1056 |
level int |
| 1057 |
isBlank bool |
| 1058 |
} |
| 1059 |
|
| 1060 |
func isBlankLine(lineNum, level int, stats []lineStat) bool { |
| 1061 |
l := len(stats) |
| 1062 |
if l == 0 { |
| 1063 |
return true |
| 1064 |
} |
| 1065 |
for i := l - 1 - level; i >= 0; i-- { |
| 1066 |
s := stats[i] |
| 1067 |
if s.lineNum == lineNum && s.level <= level { |
| 1068 |
return s.isBlank |
| 1069 |
} else if s.lineNum < lineNum { |
| 1070 |
break |
| 1071 |
} |
| 1072 |
} |
| 1073 |
return false |
| 1074 |
} |
| 1075 |
|
| 1076 |
func (p *parser) parseBlocks(parent ast.Node, reader text.Reader, pc Context) { |
| 1077 |
pc.SetOpenedBlocks(nil) |
| 1078 |
blankLines := make([]lineStat, 0, 128) |
| 1079 |
for { |
| 1080 |
_, _, ok := reader.SkipBlankLines() |
| 1081 |
if !ok { |
| 1082 |
return |
| 1083 |
} |
| 1084 |
|
| 1085 |
if p.openBlocks(parent, true, reader, pc) != newBlocksOpened { |
| 1086 |
return |
| 1087 |
} |
| 1088 |
reader.AdvanceLine() |
| 1089 |
blankLines = blankLines[0:0] |
| 1090 |
for { |
| 1091 |
openedBlocks := pc.OpenedBlocks() |
| 1092 |
l := len(openedBlocks) |
| 1093 |
if l == 0 { |
| 1094 |
break |
| 1095 |
} |
| 1096 |
lastIndex := l - 1 |
| 1097 |
for i := range l { |
| 1098 |
be := openedBlocks[i] |
| 1099 |
line, _ := reader.PeekLine() |
| 1100 |
if line == nil { |
| 1101 |
p.closeBlocks(lastIndex, 0, reader, pc) |
| 1102 |
reader.AdvanceLine() |
| 1103 |
return |
| 1104 |
} |
| 1105 |
lineNum, _ := reader.Position() |
| 1106 |
blankLines = append(blankLines, lineStat{lineNum, i, util.IsBlank(line)}) |
| 1107 |
|
| 1108 |
|
| 1109 |
if !ast.IsParagraph(be.Node) { |
| 1110 |
state := be.Parser.Continue(be.Node, reader, pc) |
| 1111 |
if state&Continue != 0 { |
| 1112 |
|
| 1113 |
|
| 1114 |
if state&HasChildren != 0 && i == lastIndex { |
| 1115 |
isBlank := isBlankLine(lineNum-1, i+1, blankLines) |
| 1116 |
p.openBlocks(be.Node, isBlank, reader, pc) |
| 1117 |
break |
| 1118 |
} |
| 1119 |
continue |
| 1120 |
} |
| 1121 |
} |
| 1122 |
|
| 1123 |
isBlank := isBlankLine(lineNum-1, i, blankLines) |
| 1124 |
thisParent := parent |
| 1125 |
if i != 0 { |
| 1126 |
thisParent = openedBlocks[i-1].Node |
| 1127 |
} |
| 1128 |
lastNode := openedBlocks[lastIndex].Node |
| 1129 |
result := p.openBlocks(thisParent, isBlank, reader, pc) |
| 1130 |
if result != paragraphContinuation { |
| 1131 |
|
| 1132 |
|
| 1133 |
if openedBlocks[lastIndex].Node != lastNode { |
| 1134 |
lastIndex-- |
| 1135 |
} |
| 1136 |
p.closeBlocks(lastIndex, i, reader, pc) |
| 1137 |
} |
| 1138 |
break |
| 1139 |
} |
| 1140 |
|
| 1141 |
reader.AdvanceLine() |
| 1142 |
} |
| 1143 |
} |
| 1144 |
} |
| 1145 |
|
| 1146 |
func (p *parser) walkBlock(block ast.Node, cb func(node ast.Node)) { |
| 1147 |
for c := block.FirstChild(); c != nil; c = c.NextSibling() { |
| 1148 |
p.walkBlock(c, cb) |
| 1149 |
} |
| 1150 |
cb(block) |
| 1151 |
} |
| 1152 |
|
| 1153 |
const ( |
| 1154 |
lineBreakHard uint8 = 1 << iota |
| 1155 |
lineBreakSoft |
| 1156 |
lineBreakVisible |
| 1157 |
) |
| 1158 |
|
| 1159 |
func (p *parser) parseBlock(block text.BlockReader, parent ast.Node, pc Context) { |
| 1160 |
if parent.IsRaw() { |
| 1161 |
return |
| 1162 |
} |
| 1163 |
escaped := false |
| 1164 |
source := block.Source() |
| 1165 |
block.Reset(parent.Lines()) |
| 1166 |
for { |
| 1167 |
retry: |
| 1168 |
line, _ := block.PeekLine() |
| 1169 |
if line == nil { |
| 1170 |
break |
| 1171 |
} |
| 1172 |
lineLength := len(line) |
| 1173 |
var lineBreakFlags uint8 |
| 1174 |
hasNewLine := line[lineLength-1] == '\n' |
| 1175 |
if ((lineLength >= 3 && line[lineLength-2] == '\\' && |
| 1176 |
line[lineLength-3] != '\\') || (lineLength == 2 && line[lineLength-2] == '\\')) && hasNewLine { |
| 1177 |
lineLength -= 2 |
| 1178 |
lineBreakFlags |= lineBreakHard | lineBreakVisible |
| 1179 |
} else if ((lineLength >= 4 && line[lineLength-3] == '\\' && line[lineLength-2] == '\r' && |
| 1180 |
line[lineLength-4] != '\\') || (lineLength == 3 && line[lineLength-3] == '\\' && line[lineLength-2] == '\r')) && |
| 1181 |
hasNewLine { |
| 1182 |
lineLength -= 3 |
| 1183 |
lineBreakFlags |= lineBreakHard | lineBreakVisible |
| 1184 |
} else if lineLength >= 3 && line[lineLength-3] == ' ' && line[lineLength-2] == ' ' && |
| 1185 |
hasNewLine { |
| 1186 |
lineLength -= 3 |
| 1187 |
lineBreakFlags |= lineBreakHard |
| 1188 |
} else if lineLength >= 4 && line[lineLength-4] == ' ' && line[lineLength-3] == ' ' && |
| 1189 |
line[lineLength-2] == '\r' && hasNewLine { |
| 1190 |
lineLength -= 4 |
| 1191 |
lineBreakFlags |= lineBreakHard |
| 1192 |
} else if hasNewLine { |
| 1193 |
|
| 1194 |
|
| 1195 |
|
| 1196 |
lineBreakFlags |= lineBreakSoft |
| 1197 |
} |
| 1198 |
|
| 1199 |
l, startPosition := block.Position() |
| 1200 |
n := 0 |
| 1201 |
for i := range lineLength { |
| 1202 |
c := line[i] |
| 1203 |
if c == '\n' { |
| 1204 |
break |
| 1205 |
} |
| 1206 |
isSpace := util.IsSpace(c) && c != '\r' && c != '\n' |
| 1207 |
isPunct := util.IsPunct(c) |
| 1208 |
if (isPunct && !escaped) || isSpace && !(escaped && p.escapedSpace) || i == 0 { |
| 1209 |
parserChar := c |
| 1210 |
if isSpace || (i == 0 && !isPunct) { |
| 1211 |
parserChar = ' ' |
| 1212 |
} |
| 1213 |
ips := p.inlineParsers[parserChar] |
| 1214 |
if ips != nil { |
| 1215 |
block.Advance(n) |
| 1216 |
n = 0 |
| 1217 |
savedLine, savedPosition := block.Position() |
| 1218 |
if i != 0 { |
| 1219 |
_, currentPosition := block.Position() |
| 1220 |
ast.MergeOrAppendTextSegment(parent, startPosition.Between(currentPosition)) |
| 1221 |
_, startPosition = block.Position() |
| 1222 |
} |
| 1223 |
var inlineNode ast.Node |
| 1224 |
for _, ip := range ips { |
| 1225 |
inlineNode = ip.Parse(parent, block, pc) |
| 1226 |
if inlineNode != nil { |
| 1227 |
if inlineNode.Pos() < 0 { |
| 1228 |
inlineNode.(interface{ SetPos(int) }).SetPos(startPosition.Start) |
| 1229 |
} |
| 1230 |
break |
| 1231 |
} |
| 1232 |
block.SetPosition(savedLine, savedPosition) |
| 1233 |
} |
| 1234 |
if inlineNode != nil { |
| 1235 |
parent.AppendChild(parent, inlineNode) |
| 1236 |
goto retry |
| 1237 |
} |
| 1238 |
} |
| 1239 |
} |
| 1240 |
if escaped { |
| 1241 |
escaped = false |
| 1242 |
n++ |
| 1243 |
continue |
| 1244 |
} |
| 1245 |
|
| 1246 |
if c == '\\' { |
| 1247 |
escaped = true |
| 1248 |
n++ |
| 1249 |
continue |
| 1250 |
} |
| 1251 |
|
| 1252 |
escaped = false |
| 1253 |
n++ |
| 1254 |
} |
| 1255 |
if n != 0 { |
| 1256 |
block.Advance(n) |
| 1257 |
} |
| 1258 |
currentL, currentPosition := block.Position() |
| 1259 |
if l != currentL { |
| 1260 |
continue |
| 1261 |
} |
| 1262 |
diff := startPosition.Between(currentPosition) |
| 1263 |
var text *ast.Text |
| 1264 |
if lineBreakFlags&(lineBreakHard|lineBreakVisible) == lineBreakHard|lineBreakVisible { |
| 1265 |
text = ast.NewTextSegment(diff) |
| 1266 |
} else { |
| 1267 |
text = ast.NewTextSegment(diff.TrimRightSpace(source)) |
| 1268 |
} |
| 1269 |
text.SetSoftLineBreak(lineBreakFlags&lineBreakSoft != 0) |
| 1270 |
text.SetHardLineBreak(lineBreakFlags&lineBreakHard != 0) |
| 1271 |
parent.AppendChild(parent, text) |
| 1272 |
block.AdvanceLine() |
| 1273 |
} |
| 1274 |
|
| 1275 |
ProcessDelimiters(nil, pc) |
| 1276 |
for _, ip := range p.closeBlockers { |
| 1277 |
ip.CloseBlock(parent, block, pc) |
| 1278 |
} |
| 1279 |
|
| 1280 |
} |