mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-04-25 07:07:32 -04:00
fix: support exporting more content to markdown (#7333)
* fix: support exporting to markdown with multiple images * fix: support exporting to markdown with database * fix: support exporting to markdown with date or reminder * fix: support exporting to markdown with subpage and page reference * chore: add some testing for markdown parser * chore: add testing for exporting markdown with databse as csv
This commit is contained in:
parent
04e3246976
commit
552dba5abe
14 changed files with 383 additions and 28 deletions
|
@ -1,5 +1,13 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:appflowy/plugins/document/presentation/editor_plugins/parsers/sub_page_node_parser.dart';
|
||||
import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
|
||||
import 'package:appflowy_backend/log.dart';
|
||||
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||
import 'package:archive/archive.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
|
||||
Document customMarkdownToDocument(
|
||||
String markdown, {
|
||||
|
@ -14,17 +22,66 @@ Document customMarkdownToDocument(
|
|||
);
|
||||
}
|
||||
|
||||
String customDocumentToMarkdown(Document document) {
|
||||
return documentToMarkdown(
|
||||
Future<String> customDocumentToMarkdown(
|
||||
Document document, {
|
||||
String path = '',
|
||||
AsyncValueSetter<Archive>? onArchive,
|
||||
}) async {
|
||||
final List<Future<ArchiveFile>> fileFutures = [];
|
||||
|
||||
/// create root Archive and directory
|
||||
final id = document.root.id,
|
||||
archive = Archive(),
|
||||
resourceDir = ArchiveFile('$id/', 0, null)..isFile = false,
|
||||
fileName = p.basenameWithoutExtension(path),
|
||||
dirName = resourceDir.name;
|
||||
|
||||
final markdown = documentToMarkdown(
|
||||
document,
|
||||
customParsers: [
|
||||
const MathEquationNodeParser(),
|
||||
const CalloutNodeParser(),
|
||||
const ToggleListNodeParser(),
|
||||
const CustomImageNodeParser(),
|
||||
CustomImageNodeFileParser(fileFutures, dirName),
|
||||
CustomMultiImageNodeFileParser(fileFutures, dirName),
|
||||
GridNodeParser(fileFutures, dirName),
|
||||
BoardNodeParser(fileFutures, dirName),
|
||||
CalendarNodeParser(fileFutures, dirName),
|
||||
const CustomParagraphNodeParser(),
|
||||
const SubPageNodeParser(),
|
||||
const SimpleTableNodeParser(),
|
||||
const LinkPreviewNodeParser(),
|
||||
const FileBlockNodeParser(),
|
||||
],
|
||||
);
|
||||
|
||||
/// create resource directory
|
||||
if (fileFutures.isNotEmpty) archive.addFile(resourceDir);
|
||||
|
||||
/// add markdown file to Archive
|
||||
archive.addFile(ArchiveFile.string('$fileName-$id.md', markdown));
|
||||
|
||||
for (final fileFuture in fileFutures) {
|
||||
archive.addFile(await fileFuture);
|
||||
}
|
||||
if (archive.isNotEmpty && path.isNotEmpty) {
|
||||
if (onArchive == null) {
|
||||
final zipEncoder = ZipEncoder();
|
||||
final zip = zipEncoder.encode(archive);
|
||||
if (zip != null) {
|
||||
final zipFile = await File(path).writeAsBytes(zip);
|
||||
if (Platform.isIOS) {
|
||||
await Share.shareUri(zipFile.uri);
|
||||
await zipFile.delete();
|
||||
} else if (Platform.isAndroid) {
|
||||
await Share.shareXFiles([XFile(zipFile.path)]);
|
||||
await zipFile.delete();
|
||||
}
|
||||
Log.info('documentToMarkdownFiles to $path');
|
||||
}
|
||||
} else {
|
||||
await onArchive.call(archive);
|
||||
}
|
||||
}
|
||||
return markdown;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue