mirror of
https://github.com/amitwh/markdown-converter.git
synced 2026-08-23 23:10:17 +05:30
feat(editor): add CSV-to-markdown-table toolbar converter
Amit Haridas
This commit is contained in:
@@ -12,6 +12,7 @@ const hljs = require('highlight.js');
|
||||
const { createEditor } = require('./editor/codemirror-setup');
|
||||
const { undo, redo } = require('@codemirror/commands');
|
||||
const { showMediaOperationsDialog } = require('./renderer/media-operations-dialog');
|
||||
const { csvToMarkdownTable } = require('./utils/csv-to-markdown-table');
|
||||
|
||||
/**
|
||||
* Toggle body classes that drive the monospace font + ligatures CSS tokens.
|
||||
@@ -1212,6 +1213,11 @@ class TabManager {
|
||||
this.insertTable();
|
||||
});
|
||||
|
||||
// CSV to Table (converts the selected CSV text in place)
|
||||
document.getElementById('btn-csv-table').addEventListener('click', () => {
|
||||
this.convertSelectionToTable();
|
||||
});
|
||||
|
||||
// Strikethrough
|
||||
document.getElementById('btn-strikethrough').addEventListener('click', () => {
|
||||
this.wrapSelection('~~', '~~');
|
||||
@@ -1284,6 +1290,26 @@ class TabManager {
|
||||
this.insertAtCursor(table);
|
||||
}
|
||||
|
||||
// Convert the selected CSV text into a markdown table in place
|
||||
convertSelectionToTable() {
|
||||
const tab = this.tabs.get(this.activeTabId);
|
||||
if (!tab?.editorView) return;
|
||||
const view = tab.editorView;
|
||||
const { from, to } = view.state.selection.main;
|
||||
const selectedText = view.state.sliceDoc(from, to);
|
||||
if (!selectedText.trim()) return;
|
||||
const table = csvToMarkdownTable(selectedText);
|
||||
if (!table) return;
|
||||
view.dispatch({
|
||||
changes: {
|
||||
from,
|
||||
to,
|
||||
insert: table,
|
||||
},
|
||||
});
|
||||
view.focus();
|
||||
}
|
||||
|
||||
// Insert a code block
|
||||
insertCodeBlock() {
|
||||
const tab = this.tabs.get(this.activeTabId);
|
||||
|
||||
Reference in New Issue
Block a user