dart-pad icon indicating copy to clipboard operation
dart-pad copied to clipboard

Inject_embed: `run-dartpad` info string breaks syntax highlighting

Open chalin opened this issue 4 years ago • 1 comments

From the Embedding Guide, Converting code blocks to DartPad section:

Step 2: Add a code snippet

In Markdown:

```run-dartpad:theme-light:mode-flutter:run-true
main() => print("Hello, World!");
```

Using an info string of run-dartpad rather than dart breaks syntax highlighting, both in the IDE and the generated site (users will get to see the original code block in cases where DartPad hasn't been injected yet, or hasn't been successfully injected). Users see this:

Instead of this:

Probably shouldn't happen that often, but still. /cc @kwalrath @legalcodes


It would be great if we could:

  • Leave the info string as dart, and
  • Have the option of triggering the injector by attaching classes to a parent element.

For example:

<div class="run-dartpad:theme-light:mode-flutter:run-true">
```dart
main() => print("Hello, World!");
```
</div>

Or using a Jekyll-specific syntax:

{:.run-dartpad:theme-light:mode-flutter:run-true}
```dart
main() => print("Hello, World!");
```

Jekyll renders this as:

<pre class="run-dartpad">
<code class="language-dart">main() => ...
</code></pre>

chalin avatar Nov 14 '19 23:11 chalin

I know this issue is rather old but I also encountered this problem. Here is how I was able to solve it for my system (highlight.js v 11.5.1)

```lang-dart:run-dartpad:theme-light:width-100%:height-500px:mode-inline
enum SomeEnum {
//...
}
 ```

Highlight.js picks up the lang-dart part and the DartPad injector is happy as well.

devmil avatar May 13 '22 15:05 devmil