Arduino Syntax Highlighter (Code to HTML)
NOUVEAUArduino syntax highlighter that turns .ino and C++ code into colored HTML with line numbers, light or dark themes, inline styles or CSS classes.
Fonctionne à 100 % dans votre navigateur — vos données ne sont jamais envoyées ni stockées sur nos serveurs.
Cet outil n'est pas encore entièrement traduit : une partie du texte est encore en anglais. L'outil lui-même fonctionne de la même façon dans toutes les langues.
Preview
1#include <Wire.h>
2#define BUTTON_PIN 2
3
4volatile bool pressed = false; // set in the ISR
5const unsigned long DEBOUNCE_MS = 50UL;
6
7void onPress() {
8 pressed = true;
9}
10
11void setup() {
12 Serial.begin(115200);
13 pinMode(LED_BUILTIN, OUTPUT);
14 pinMode(BUTTON_PIN, INPUT_PULLUP);
15 attachInterrupt(digitalPinToInterrupt(BUTTON_PIN), onPress, FALLING);
16}
17
18void loop() {
19 if (pressed) {
20 pressed = false;
21 int raw = analogRead(A0);
22 float volts = raw * (5.0 / 1023.0);
23 Serial.print(F("A0 = "));
24 Serial.println(volts, 2);
25 digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
26 delay(DEBOUNCE_MS);
27 }
28}- Keyword (3)
- Type (8)
- Constant (10)
- Arduino function (14)
- Arduino object (3)
- Function call (1)
- String / char (2)
- Number (6)
- Comment (1)
- Preprocessor (2)
- Operator (12)
Self-contained: paste into a blog editor, forum post, email or CMS that strips <style> tags.
<pre style="margin:0;padding:12px 16px;background:#ffffff;color:#434f54;font-family:ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;font-size:14px;line-height:1.5;tab-size:2;overflow-x:auto;border-radius:6px"><code><span style="display:inline-block;min-width:2ch;margin-right:16px;text-align:right;color:#95a5a6;user-select:none">1</span><span style="color:#728e00;font-weight:600">#include</span> <span style="color:#005c5f"><Wire.h></span>
<span style="display:inline-block;min-width:2ch;margin-right:16px;text-align:right;color:#95a5a6;user-select:none">2</span><span style="color:#728e00;font-weight:600">#define</span> BUTTON_PIN <span style="color:#8a7b52">2</span>
<span style="display:inline-block;min-width:2ch;margin-right:16px;text-align:right;color:#95a5a6;user-select:none">3</span>
<span style="display:inline-block;min-width:2ch;margin-right:16px;text-align:right;color:#95a5a6;user-select:none">4</span><span style="color:#728e00;font-weight:600">volatile</span> <span style="color:#00979c">bool</span> pressed <span style="color:#434f54">=</span> <span style="color:#00979c">false</span>; <span style="color:#95a5a6;font-style:italic">// set in the ISR</span>
<span style="display:inline-block;min-width:2ch;margin-right:16px;text-align:right;color:#95a5a6;user-select:none">5</span><span style="color:#728e00;font-weight:600">const</span> <span style="color:#00979c">unsigned</span> <span style="color:#00979c">long</span> DEBOUNCE_MS <span style="color:#434f54">=</span> <span style="color:#8a7b52">50UL</span>;
<span style="display:inline-block;min-width:2ch;margin-right:16px;text-align:right;color:#95a5a6;user-select:none">6</span>
<span style="display:inline-block;min-width:2ch;margin-right:16px;text-align:right;color:#95a5a6;user-select:none">7</span><span style="color:#00979c">void</span> <span style="color:#434f54">onPress</span>() {
<span style="display:inline-block;min-width:2ch;margin-right:16px;text-align:right;color:#95a5a6;user-select:none">8</span> pressed <span style="color:#434f54">=</span> <span style="color:#00979c">true</span>;
<span style="display:inline-block;min-width:2ch;margin-right:16px;text-align:right;color:#95a5a6;user-select:none">9</span>}
<span style="display:inline-block;min-width:2ch;margin-right:16px;text-align:right;color:#95a5a6;user-select:none">10</span>
<span style="display:inline-block;min-width:2ch;margin-right:16px;text-align:right;color:#95a5a6;user-select:none">11</span><span style="color:#00979c">void</span> <span style="color:#d35400">setup</span>() {
<span style="display:inline-block;min-width:2ch;margin-right:16px;text-align:right;color:#95a5a6;user-select:none">12</span> <span style="color:#d35400">Serial</span><span style="color:#434f54">.</span><span style="color:#d35400">begin</span>(<span style="color:#8a7b52">115200</span>);
<span style="display:inline-block;min-width:2ch;margin-right:16px;text-align:right;color:#95a5a6;user-select:none">13</span> <span style="color:#d35400">pinMode</span>(<span style="color:#00979c">LED_BUILTIN</span>, <span style="color:#00979c">OUTPUT</span>);
<span style="display:inline-block;min-width:2ch;margin-right:16px;text-align:right;color:#95a5a6;user-select:none">14</span> <span style="color:#d35400">pinMode</span>(BUTTON_PIN, <span style="color:#00979c">INPUT_PULLUP</span>);
<span style="display:inline-block;min-width:2ch;margin-right:16px;text-align:right;color:#95a5a6;user-select:none">15</span> <span style="color:#d35400">attachInterrupt</span>(<span style="color:#d35400">digitalPinToInterrupt</span>(BUTTON_PIN), onPress, <span style="color:#00979c">FALLING</span>);
<span style="display:inline-block;min-width:2ch;margin-right:16px;text-align:right;color:#95a5a6;user-select:none">16</span>}
<span style="display:inline-block;min-width:2ch;margin-right:16px;text-align:right;color:#95a5a6;user-select:none">17</span>
<span style="display:inline-block;min-width:2ch;margin-right:16px;text-align:right;color:#95a5a6;user-select:none">18</span><span style="color:#00979c">void</span> <span style="color:#d35400">loop</span>() {
<span style="display:inline-block;min-width:2ch;margin-right:16px;text-align:right;color:#95a5a6;user-select:none">19</span> <span style="color:#728e00;font-weight:600">if</span> (pressed) {
<span style="display:inline-block;min-width:2ch;margin-right:16px;text-align:right;color:#95a5a6;user-select:none">20</span> pressed <span style="color:#434f54">=</span> <span style="color:#00979c">false</span>;
<span style="display:inline-block;min-width:2ch;margin-right:16px;text-align:right;color:#95a5a6;user-select:none">21</span> <span style="color:#00979c">int</span> raw <span style="color:#434f54">=</span> <span style="color:#d35400">analogRead</span>(<span style="color:#00979c">A0</span>);
<span style="display:inline-block;min-width:2ch;margin-right:16px;text-align:right;color:#95a5a6;user-select:none">22</span> <span style="color:#00979c">float</span> volts <span style="color:#434f54">=</span> raw <span style="color:#434f54">*</span> (<span style="color:#8a7b52">5.0</span> <span style="color:#434f54">/</span> <span style="color:#8a7b52">1023.0</span>);
<span style="display:inline-block;min-width:2ch;margin-right:16px;text-align:right;color:#95a5a6;user-select:none">23</span> <span style="color:#d35400">Serial</span><span style="color:#434f54">.</span><span style="color:#d35400">print</span>(<span style="color:#d35400">F</span>(<span style="color:#005c5f">"A0 = "</span>));
<span style="display:inline-block;min-width:2ch;margin-right:16px;text-align:right;color:#95a5a6;user-select:none">24</span> <span style="color:#d35400">Serial</span><span style="color:#434f54">.</span><span style="color:#d35400">println</span>(volts, <span style="color:#8a7b52">2</span>);
<span style="display:inline-block;min-width:2ch;margin-right:16px;text-align:right;color:#95a5a6;user-select:none">25</span> <span style="color:#d35400">digitalWrite</span>(<span style="color:#00979c">LED_BUILTIN</span>, <span style="color:#434f54">!</span><span style="color:#d35400">digitalRead</span>(<span style="color:#00979c">LED_BUILTIN</span>));
<span style="display:inline-block;min-width:2ch;margin-right:16px;text-align:right;color:#95a5a6;user-select:none">26</span> <span style="color:#d35400">delay</span>(DEBOUNCE_MS);
<span style="display:inline-block;min-width:2ch;margin-right:16px;text-align:right;color:#95a5a6;user-select:none">27</span> }
<span style="display:inline-block;min-width:2ch;margin-right:16px;text-align:right;color:#95a5a6;user-select:none">28</span>}</code></pre>Exemples rapides
Des entrées typiques et les résultats produits par cet outil.
Présentation
This Arduino syntax highlighter converts a sketch into colored HTML you can paste into a blog post, project write-up, course page or forum that accepts HTML. It recognizes C++ keywords and types, Arduino types such as byte and uint8_t, core functions like pinMode, digitalWrite, analogRead and millis, objects such as Serial and Wire with their methods, constants like HIGH, OUTPUT and A0, preprocessor lines, strings, numbers and comments.
Choose an Arduino-style light theme or a dark theme, turn line numbers on or off, and export either self-contained HTML with inline styles or lean markup with ino-* classes plus a matching stylesheet. The code is read by a real C/C++ tokenizer, so raw strings, escaped quotes and block comments are colored correctly, and every character is HTML-escaped. Nothing leaves your browser.
Pourquoi utiliser cet outil ?
- Share readable sketches in blogs and docs
- Arduino functions and constants get their own colors
- Inline styles survive editors that strip CSS
- Light and dark themes with optional line numbers
- Private: highlighting runs locally
Fonctionnalités
Four themes
Arduino-style Light, GitHub Light, One Dark and Monokai, previewed live.
Arduino-aware
Separate colors for core API functions, Serial/Wire/SPI objects and constants such as HIGH, INPUT_PULLUP and A0.
Inline-style HTML
Every color is written into the markup, so it renders in CMS editors and email.
Classes + CSS
Smaller markup with ino-kw, ino-api, ino-str… classes and a copyable stylesheet.
Line numbers
Optional, right-aligned and not selected when readers copy the code.
Escaped output
<, > and & in your code are escaped, so #include <Wire.h> cannot break the page.
Mode d'emploi
Paste the sketch
Paste Arduino or C++ code, or press Sample.
Pick theme and options
Choose a theme, tab width and whether to show line numbers.
Choose the HTML format
Inline styles for editors and email, or Classes + CSS for your own site.
Copy
Use Copy HTML (and Copy CSS for the class format) and paste it into your page.