Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Upload md File and process upload in browser #53

Closed
BenutzerEinsZweiDrei opened this issue Sep 12, 2024 · 1 comment
Closed
Assignees

Comments

@BenutzerEinsZweiDrei
Copy link

I think it could be a rly great addition if people dont have to look for hosting
But instead can upload a file which is processed in js

Chatgpt says it works like this

With <input type="file" id="mdFile" accept=".md" />

// Get the file input and content display elements
const fileInput = document.getElementById('mdFile');
const fileContentDisplay = document.getElementById('fileContent');

// Listen for file input changes (file upload)
fileInput.addEventListener('change', (event) => {
  const file = event.target.files[0]; // Get the first file

  // Ensure the file is a markdown file
  if (file && file.type === "") {
    // Create a FileReader to read the file content
    const reader = new FileReader();

    // Define what happens when the file is read
    reader.onload = function(e) {
      const fileContent = e.target.result; // File content as text
      displayMarkdown(fileContent); // Call function to display the content
    };

    // Read the file as text
    reader.readAsText(file);
  } else {
    alert('Please upload a valid markdown (.md) file');
  }
});

// Function to display markdown content in the page
function displayMarkdown(content) {
  // Display the raw markdown text (you could parse this for richer rendering)
  fileContentDisplay.textContent = content;

  // Optionally: If you want to render Markdown to HTML using a library like marked.js:
  // const htmlContent = marked(content);
  // fileContentDisplay.innerHTML = htmlContent;
}

then just pass the markdown to the beforeEach hook

https://github.com/docsifyjs/docsify/blob/develop/docs/write-a-plugin.md#beforeeach

@paulhibbitts paulhibbitts self-assigned this Sep 12, 2024
@paulhibbitts
Copy link
Contributor

Thanks @BenutzerEinsZweiDrei for your continued interest in Docsify-This!

For this type of advanced functionality, I would suggest you make your own instance of Docsify-This (which is intended to serve as a entry point to Markdown publishing) right on GitHub and then try out this technique and if successful use that same instance to provide that functionality.

I've got the basics of setting up your own instance outlined at https://docsify-this.net/#/?id=looking-for-even-more-customization-and-control.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants