Closed jnerlich closed 8 months ago
https://daringfireball.net/projects/markdown/syntax#precode The code block is composed of pre and code tags in regular markdown.
Maybe you can add a custom rule, here are the builtin code block rule you can refer to: https://github.com/jarontai/html2md/blob/master/lib/src/rules.dart#L199
Thanks. Sorry for the silly question but getStyleOption
is shown as error.
I tried to define the rule as follows:
final Rule indentedCodeBlock = Rule('indentedCodeBlock', filterFn: (node) {
return getStyleOption('codeBlockStyle') == 'indented' &&
node.parentElName == 'pre';
}, replacement: (content, node) {
var children = node.childNodes().toList();
if (children.length == 1) {
return '\n\n ' +
children.first.textContent.replaceAll(RegExp(r'\n'), '\n ') +
'\n\n';
} else {
var result = '\n\n ';
for (var child in children) {
var text = child.textContent;
if (child != children.last) {
text = text.replaceAll(RegExp(r'\n'), '\n ');
}
result += text;
}
return result + '\n\n';
}
});
Also copying your import statement does not compile:
import 'package:html2md/html2md.dart';
import 'package:http/http.dart' as http;
import 'package:html/parser.dart' as htmlParser;
import 'package:html/dom.dart' as htmlDom;
import 'package:html2md/html2md.dart' as html2md;
import 'dart:io';
import 'options.dart' show getStyleOption;
getStyleOption('codeBlockStyle') == 'indented'
is for builtin rule, you can remove it.
Thanks, that works for me. Thanks for your tooling and your answers.
Closing
Hi, I'm using your library to convert Wiki pages to Markdown, for example :https://wiki.eclipse.org/Version_Numbering
If a \