Render web code in a your page (javascript, html, ...)

Undraw My Documents

About

webcode is a component that permits to render the output of code such as HTML, Javascript or CSS.

By enclosing code blocks by a webcode block, the plugin will add the result at the end (after the last webcode tag).

Example

HTML

<webcode>
This is the HTML
<code html>
<span style="font-size:30pt">&#x1F600;</span>
</code>
Output:
</webcode>

  • Result

This is the HTML

<span style="font-size:30pt">&#x1F600;</span>

Output:

Javascript

webcode supports javascript and captures the console call (log 1) and table 2)) to print them on the web page in a console area (Gray box).

Example:

<webcode>
  * in a javascript code block
<code javascript>
console.log("Javascript Code block");
</code>
  * and also in html code block
<code html>
<script>console.log("Html code block");</script>
</code>
  * The output of the console is also printed on the page.
</webcode>



The result is:

  • in a javascript code block
console.log("Javascript Code block");
  • and also in html code block
<script>console.log("Html code block");</script>
  • The output of the console is also printed on the page.

Console.table

console.table 3) is supported with an array of objects or primitives. There is no second argument.

Example:

<webcode>
    <code javascript>
        let tabularData = [
            {name: "foo", short: "f"},
            {name: "bar", short: "b"}
        ];
        console.table(tabularData);
    </code>
</webcode>
  • This markup will output:
        let tabularData = [
            {name: "foo", short: "f"},
            {name: "bar", short: "b"}
        ];
        console.table(tabularData);
    

Across section

You can use webcode across section (ie with heading)

Example:

  • the following markup
<webcode>
===== Javascript =====
```javascript
var colors = [ "blue", "green" ];
for (const [index, value] of colors.entries()) {
  console.log(index+", "+value+"\n");
}
```
===== Result =====
</webcode>
  • will output:

Syntax

Webcode Syntax

<webcode type name="A Name" width=100% height=250px>

    <!-- wiki syntax with css or html block code. -->
    All syntax are permitted between blocks

    <!-- css code block -->
    <code css>
    </code>

    <!-- html code block -->
    <code html>
    </code>

    <!-- javascript or babel code block -->
    <code javascript> <!-- or <code babel> -->
    </code>

    <!-- Wiki Markup -->
    <code dw>

    <!-- Code Block not displayed-->
    <code language [display="none"]>
    </code>

</webcode>

Webcode attributes

The allowed webcode attributes are:

    • story (default): The rendering will output the content inside the webcode elements and add the result after the closing webcode code.
    • result: The rendering will suppress the content inside the webcode elements and will show only the result after the closing webcode code.
    • inject: The HTML and Javascript will be injected on the page
  • the following attributes of the iframe element
    • name. It will be added as a suffix
    • frameborder (default to 0)
    • width (default to 100%)
    • height (The height is automatically adjusted if not set)
    • scrolling

External resources

For external resources such as Css or Js file, this is recommended to put them in a hidden HTML code block.

Example with Bootstrap:

<code html display="none">
<!-- CSS  -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
<!-- JavaScript -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-pprn3073KE6tl6bjs2QrFaJGz5/SUsLqktiwsUTF55Jfv3qYSDhgCecCxMW52nD2" crossorigin="anonymous"></script>
</code>

code attributes

The supported code block syntax is

<code lang filePath [display="none"]>
</code>

where:

  • lang can be:
    • html
    • xml (will be seen as XHTML)
    • css
    • javascript or babel (but not both in a webcode)
    • dw (for dokuwiki)
  • display=“none” will not display the code block (in this case file name and other attributes should not be used)

Security

To save this syntax, you need to be:

Language Support

Babel

When a code block use Babel as language, the plugin will add the babel.min.js version 6 to the external resources.

You cannot have a Babel and a Javascript Block in the same webcode block.

Support

Parsing problem?

The characters ''<, >, ", ', \, and &'' should be escaped in string literals.

Example:

  • In the below literal, the character / should be escaped
let fragment = '</script>';
  • The right way is to write it:
let fragment = '<\/script>';

Why? Because the code is executed on the HTML page, they will interfere with the HTML parser.




Showcase yourself and your brand

Get free news, tips, and tricks
to create a remarkable experience for your readers.




Related HowTo's
Undraw Animating
How to add HTML , Css, and Javascript directly to the content of your pages?

This article shows you how you can add HTML, CSS, or Javascript to the content of your markup page.


Recommended Pages
Undraw My Documents
ComboStrap UI - Block

A block component is a component that wraps/encapsulate: content such as text, image,... other block component If the component should start at a new line or expand on multiple line and you can...
Undraw My Documents
ComboStrap UI - Code

The code component permits to format block of code and add features such as: syntax highlighting clipboard copy line numbering You can create block of code like this one: HTMLwebcode HTML...
Undraw My Documents
Create diagram with mermaid

This component will render mermaid diagram
Undraw My Documents
Designer

A designer is a person that has elevated privilege in order to be able to use HTML and Javascript. A designer may: inject HTML with the webcode upload svg To be a designer, the user should be...
SVG to fitViewport 1Viewport 2--------------- meet ---------------xMin*xMid*xMax*---------- meet ----------*YMin*YMid*YMax---------- slice ----------xMin*xMid*xMax*--------------- slice ---------------*YMin*YMid*YMax
How to use a SVG in ComboStrap

ComboStrap supports natively SVG and allows you to use them as image, illustration and background
Page Explorer List Name To Ui Region
Page-explorer: adding page navigation easily to your website

With the page-explorer component, you can add an explorer like panel that will list your pages in a list or collapsible tree fashion



Task Runner