Created
August 10, 2023 19:05
-
-
Save yearofthewhopper/867bd8f01c273843a65836b9d32d55a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function convertMarkdownToPlainText() { | |
// Get the active document and body | |
var body = DocumentApp.getActiveDocument().getBody(); | |
// Retrieve the text from the document | |
var text = body.getText(); | |
// Replace common Markdown patterns with plain text equivalents | |
text = text.replace(/__([^_]+)__/g, '$1'); // bold | |
text = text.replace(/\*\*([^\*]+)\*\*/g, '$1'); // bold | |
text = text.replace(/_([^_]+)_/g, '$1'); // italic | |
text = text.replace(/\*([^\*]+)\*/g, '$1'); // italic | |
text = text.replace(/\#\#([^\#]+)\#\#/g, '$1'); // headers | |
text = text.replace(/\#\#\#([^\#]+)\#\#\#/g, '$1'); // smaller headers | |
// Set the new text | |
body.setText(text); | |
} | |
function onOpen() { | |
var ui = DocumentApp.getUi(); | |
// Create a new menu in Google Docs with a single menu item | |
ui.createMenu('Markdown Converter') | |
.addItem('Convert to Plain Text', 'convertMarkdownToPlainText') | |
.addToUi(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment