(VHDL) Extract line comments marked by '--' to create a Markdown document


#22

Yes your code works. It works as-is.

difficultyis not critique to the code.
In some way it is instead a compliment.
It comments about me who is still learning Coffeescript; trying to teach myself from your code.
I am trying to understand what function methods you have used and why.


A valid argument. I know this, but ignore this fact - seeing the grammar is more important to me. There is another way to set the grammar to an open untitled page. I was just too lazy to do it that way.


Do you perhaps know how to trigger the markdown-preview after the comments were extracted?


#23

Dan, Dpo,

News: ! Both solutions work !
Before I was working on a WIn-7 machine and there it does not work as expected.
I applied both solutions, first Dan’s and then Dpo’s, to the Atom install on my Ubuntu 16.04 machine (Exact the same Atom install, all same packages, as on the Win-7 machine) and there each solution works perfectly.

Dan’s solution:

  • Atom with markdown-preview-plus (with markdown-preview disabled) - (the original installed situation) .
  • Copy Dan’s code to the init.coffee file.
  • with any VHDL file loaded into Atom, I get exactly the result as Dan shows in the screenshot he add in his reply mentioning he runs on Win-7 (15/21 Oct 21).

Dpo’s version:

  • Commented Dan’s code in the init.coffee file.
  • Un-installed Markdown-preview-plus and installed Markdown-preview-enhanced.
  • Add the code published for the parser.js file to the parser.js file.
  • Add in the Markdown-preview-enhanced settings “.vhd” to the extension list (take VHDL files as markdown).
  • Restart Atom and load a VHDL file.
  • Toggle the markdown-preview-enhanced and the comments from the VHDL show now up as markdown text in the viewer. I can save these as file.
  • Copy the “atom.commands.add …” code to the init.coffee file and restart Atom.
  • Load a VHDL file and do “CTRL-SHFT-P : custom extract doc”
  • A new text window opens (untitled) with a copy of the VHDL file but having only the comment lines with leading “–” (min-min) removed.
  • This can now be [Save]-ed or [Saved As] a markdown file.

Conclusion:

  • Both solutions work!
  • I will remove and reinstall Atom and packages on the Win-7 machine and see what happens then.
  • Both solutions have their merit.
  • Dan’s init.coffee file code can be used by people without markdown packages.
  • I like Dpo’s solution because you can see as you type VHDL code what the markdown is going to look like and the part in the init.coffee file is not even needed, right click in the viewer and save as markdown document.

As I am a coffeescript novice I still try to understand what both of you wrote and how it exactly functions with Atom.

A big THANKS to both of you for helping me with this!

Regards,

Marc


#24

Hello Marc,

Thank you for the well detailed report.
Mostly I see design engineers report in this way.

@dpo gave us two good solution, but the first suits you the best. I think you got good value from his efforts. Please consider marking that post with a LIKE… then others know which is the preferred solution without following the whole topic.

I enjoyed this excercise and the team effort.
Happy coding.
- Dan


#25

There’s an option in Markdown-Preview-Enhanced to automatically open the preview when a Markdown file is open. That should do the job.

Ps: you can set the grammar of the new editor using a minor variation on this FAQ: How can I make all new files open with a specific grammar or syntax?


#26

Hi to all,

If you wnt to use the addition to the ~/.mume/parser.js file then use the code below!
Why, well:

  • I used the code proposed by dpo successfully for a while and then suddenly, after and update to Atom or
    the preview_enhanced package I guess, markdown_preview_enhanced showed an endless looping load
    icon and nothing else.
  • Reported this on the markdown_preview_enhanced page, and after some back and forward mailing I got
    a slightly modified code back.
  • The issue in the original code: "because match might be null, calling .join on null will cause exception."
    Put the two code parts in teh same editor page and you see what’s written above.

This is the new code to uses and to put in the ~/.mume/parser.js file.

module.exports = {
onWillParseMarkdown: function(markdown) {
return new Promise((resolve, reject)=> {
const match = markdown.match(/^–.$/gm) // because match might be null, calling .join on null will cause >exception.
if (match) {
markdown = match.join(’\n’).replace(/^–(.
)/gm, ($0,$1) => $1)
}
return resolve(markdown)
})
},
onDidParseMarkdown: function(html) {
return new Promise((resolve, reject)=> {
return resolve(html)
})
}
}

REMARK: There is one thing left to tackle.
When the vhdl code contains horizontal lines created out of - characters then the added code prevent that markdown_preview_enhanced shows nice markdown text.