-
-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
HL JS Code Blocks are missing new lines and indentation #20
Comments
Thanks for the report! I'll have a look this weekend. |
Thank you! Also, the language specifier isn't extracted from the code. Let me know if you need a more complete code example to test it. |
Actually, the example is from here: https://create.arduino.cc/projecthub/123325/monitor-your-energy-bill-via-modbus-mkr-wifi-1010-and-rs485-814e5e |
I had a similar problem here and getting rid of all the
|
Should be sorted in v1.1.0! Let me know if it doesn't work for you. |
Thanks for the update! Maybe I'm doing something wrong but it still doesn't work for me with 1.1.0. Test: import nhm from 'node-html-markdown';
const { NodeHtmlMarkdown, NodeHtmlMarkdownOptions } = nhm;
const data = `<html><body><pre class="hljs arduino"><code><span><span class="hljs-comment">// Created by Alberto Perro - Officine Innesto</span>
</span><span><span class="hljs-comment">//</span>
</span><span><span class="hljs-comment">// Read integer from a modbus device holding registers</span>
</span><span><span class="hljs-keyword">float</span> readCurrent(){
</span><span> <span class="hljs-keyword">float</span> ampere = <span class="hljs-number">0.</span>;
</span><span> <span class="hljs-comment">//next command format the request and send it over RS485 </span>
</span><span> <span class="hljs-built_in">if</span> (!ModbusRTUClient.<span class="hljs-built_in">requestFrom</span>(<span class="hljs-number">0x01</span>, HOLDING_REGISTERS, <span class="hljs-number">0x0016</span>, <span class="hljs-number">2</span>))
</span><span> {
</span><span> <span class="hljs-comment">//Error Handling </span>
</span><span>
</span><span> <span class="hljs-built_in">Serial</span>.<span class="hljs-built_in">print</span>(<span class="hljs-string">"failed to read voltage! "</span>);
</span><span> <span class="hljs-built_in">Serial</span>.<span class="hljs-built_in">println</span>(ModbusRTUClient.lastError());
</span><span>
</span><span> } <span class="hljs-built_in">else</span> {
</span><span> uint16_t word1 = ModbusRTUClient.<span class="hljs-built_in">read</span>(); <span class="hljs-comment">//reading MSW from buffer</span>
</span><span> uint16_t word2 = ModbusRTUClient.<span class="hljs-built_in">read</span>(); <span class="hljs-comment">//reading LSW from buffer</span>
</span><span> int32_t milliamp = word1 << <span class="hljs-number">16</span> | word2; <span class="hljs-comment">//join words to retreive int</span>
</span><span> ampere = milliamp/<span class="hljs-number">1000.0</span>; <span class="hljs-comment">//convert to ampere </span>
</span><span> }
</span><span><span class="hljs-built_in">return</span> ampere;}
</span></code></pre></body></html>`;
console.log(NodeHtmlMarkdown.translate(data)); Prints:
|
Sorry about that. That was my mistake! I wrote it to use the non-trimmed text, and that part got wiped out. I had a feeling something was missing when rewriting that section. Should be corrected in the latest version. |
I'm using version 1.0.1 and after converting a HL JS code block of this format
...
I get the following rendering:
```
// Created by Alberto Perro - Officine Innesto//
// Read integer from a modbus device holding registersfloat readCurrent(){ float ampere = 0.; //next command format the request and send it over RS485 if (!ModbusRTUClient.requestFrom(0x01, HOLDING_REGISTERS, 0x0016, 2)) { //Error Handling Serial.print("failed to read voltage! "); Serial.println(ModbusRTUClient.lastError()); } else { uint16_t word1 = ModbusRTUClient.read(); //reading MSW from buffer uint16_t word2 = ModbusRTUClient.read(); //reading LSW from buffer int32_t milliamp = word1 << 16 | word2; //join words to retreive int ampere = milliamp/1000.0; //convert to ampere } return ampere;}
```
Is there an easy way to fix this?
The text was updated successfully, but these errors were encountered: