I have a simple project. I need the help this is a related project. I need to read an HTML file and then convert it to JSON format. I want to get the matches as code and text. How I achieve this?
In this way, I have two HTML tags
<p>In practice, it is usually a bad idea to modify global variables inside the function scope since it often is the cause of confusion and weird errors that are hard to debug.<br />
If you want to modify a global variable via a function, it is recommended to pass it as an argument and reassign the return-value.<br />
For example:</p>
<pre><code class="{python} language-{python}">a_var = 2
def a_func(some_var):
return 2**3
a_var = a_func(a_var)
print(a_var)
</code></pre>
mycode:
const fs = require('fs')
const showdown = require('showdown')
var read = fs.readFileSync('./test.md', 'utf8')
function importer(mdFile) {
var result = []
let json = {}
var converter = new showdown.Converter()
var text = mdFile
var html = converter.makeHtml(text);
for (var i = 0; i < html.length; i++) {
htmlRead = html[i]
if(html == html.match(/<p>(.*?)<\/p>/g))
json.text = html.match(/<p>(.*?)<\/p>/g)
if(html == html.match(/<pre>(.*?)<\/pre>/g))
json.code = html.match(/<pre>(.*?)<\/pre>/g
}
return html
}
console.log(importer(read))
How do I get these matches on the code?
new code : I write all the p tags in the same json, how to write each p tag into different json blocks?
$('html').each(function(){
if ($('p').text != undefined) {
json.code = $('p').text()
json.language = "Text"
}
})