blob: 7d2b94e894e1254bd705bf38e6e6a40e9c59c888 [file] [log] [blame]
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import '../ast.dart';
import '../block_parser.dart';
import '../patterns.dart';
import 'block_syntax.dart';
/// Parses atx-style headers: `## Header ##`.
class HeaderSyntax extends BlockSyntax {
@override
RegExp get pattern => headerPattern;
const HeaderSyntax();
@override
Node parse(BlockParser parser) {
final match = pattern.firstMatch(parser.current)!;
parser.advance();
final level = match[1]!.length;
final contents = UnparsedContent(match[2]!.trim());
return Element('h$level', [contents]);
}
}