PHP Classes

How to Display Documents in JSON Markup Language (JML) in HTML Web Pages Using the Package JML to HTML Renderer: Convert documents in JML format to HTML

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2025-12-18 (2 days ago) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
Version License PHP version Categories
jml-to-html-renderer 1.0Custom (specified...8.2HTML, Parsers, PHP 8
Description 

Author

This package can convert documents in JML (JSON Markup Language) format to HTML.

It provides an HTML document class that can parse a string that has a document in JML format.

The class can also output the document in HTML format.

Converting JML Code to HTML

Demonstrates how Ascoos OS takes a clean, small, safe "JML" string and automatically converts it into complete and valid HTML5.

Picture of Christos Drogidis
  Performance   Level  
Name: Christos Drogidis <contact>
Classes: 31 packages by
Country: Greece Greece
Age: ???
All time rank: 379423 in Greece Greece
Week rank: 5 Up1 in Greece Greece Up
Innovation award
Innovation award
Nominee: 17x

Winner: 2x

Instructions

Please read this example PHP script to learn how to convert JML documents into HTML.

Example

<?php
/**
 * @ASCOOS-NAME : Ascoos OS
 * @ASCOOS-VERSION : 26.0.0
 * @ASCOOS-SUPPORT : [email protected]
 * @ASCOOS-BUGS : https://issues.ascoos.com
 *
 * @CASE-STUDY : jml_to_html_renderer.php
 * @fileNo : ASCOOS-OS-CASESTUDY-SEC00268
 *
 * @desc <English> Parses JML syntax into HTML using THTML, generates full page from nested structure.
 * @desc <Greek> ??????? JML syntax ?? HTML ???? THTML, ??????? ????? ?????? ??? nested ????.
 *
 * @since PHP 8.2.0
 */
declare(strict_types=1);

use
ASCOOS\OS\Kernel\HTML\THTML;
use
ASCOOS\OS\Kernel\Files\TFilesHandler;

$properties = [
   
'output' => './generated_page.html'
];

try {
   
$html = new THTML();
   
$files = new TFilesHandler();

   
// -----------------------------------------------------------------------------
    // <English> JML as string.
    // <Greek> JML ?? ????????????.
    // -----------------------------------------------------------------------------
   
$jmlString = <<<'JML'
html:lang('en') {
  head {
    meta:charset('UTF-8')
    meta:name('viewport'),content('width=device-width, initial-scale=1.0')
    title {`Advanced Sample Page`}
    style {
      `.container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
            background-color: #f4f4f4;
        }
        .header {
            text-align: center;
            color: #333;
            padding: 10px;
            border-bottom: 2px solid #000;
        }
        .form-group {
            margin-bottom: 15px;
        }
        .form-group label {
            display: block;
            font-weight: bold;
        }
        .form-group input, .form-group select {
            width: 100%;
            padding: 8px;
            margin-top: 5px;
        }`
    }
    script {
      `function validateForm() {
            let name = document.getElementById("name").value;
            let email = document.getElementById("email").value;
            if (name === "" || email === "") {
                alert("Please fill out all fields!");
                return false;
            }
            return true;
        }`
    }
  }
  body {
    div:class('container') {
      div:class('header') {
        h1 {`Welcome to Ascoos OS Demo`}
        p {`This is a complex demo with nested elements and interactivity.`}
      }
      div:class('content') {
        h2 {`User Registration`}
        form:onsubmit('return validateForm()'),method('POST'),action('/submit') {
          div:class('form-group') {
            label:for('name') {`Name:`}
            input:type('text'),id('name'),name('name'),required('')
          }
          div:class('form-group') {
            label:for('email') {`Email:`}
            input:type('email'),id('email'),name('email'),required('')
          }
          div:class('form-group') {
            label:for('country') {`Country:`}
            select:id('country'),name('country') {
              option:value('us') {`United States`}
              option:value('gr') {`Greece`}
              option:value('de') {`Germany`}
            }
          }
          button:type('submit') {`Submit`}
        }
        br
        div:class('footer') {
          p {`© 2025 Ascoos OS. All rights reserved.`}
          br
          a:href('https://ascoos.com') {`Visit our site`}
        }
      }
    }
  }
}
JML;

   
// -----------------------------------------------------------------------------
    // <English> Parse JML string to HTML
    // <Greek> ??????? ????????????? JML ?? HTML
    // -----------------------------------------------------------------------------
   
$fullHtml = $html->fromJMLString($jmlString);
   
   
// -----------------------------------------------------------------------------
    // <English> Adds DOCTYPE manually (JML focuses on body).
    // <Greek> ????????? ??????????? ?? DOCTYPE (?? JML ?????????????? ??? body).
    // -----------------------------------------------------------------------------
   
$output = '<!DOCTYPE html>' . $fullHtml;

   
// -----------------------------------------------------------------------------
    // <English> Save to file.
    // <Greek> ?????????? ?? ??????.
    // -----------------------------------------------------------------------------
   
$files->writeToFileWithCheck($output, $properties['output']);
   
   
// -----------------------------------------------------------------------------
    // <English> Preview.
    // <Greek> ?????????????.
    // -----------------------------------------------------------------------------
   
echo "JML Parsed! Generated HTML:\n";
    echo
$output . "\n";
    echo
"Saved to: " . $properties['output'] . "\n";

   
// -----------------------------------------------------------------------------
    // <English> Free resources
    // <Greek> ???????????? ????? ??? ?????????
    // -----------------------------------------------------------------------------
   
$html->Free();
   
$files->Free();
   
} catch (
Exception $e) {
    echo
"Error: " . $e->getMessage() . "\n";
}
?>


Details

Converting JML Code to HTML

This case study demonstrates how Ascoos OS takes a clean, small, safe .jml file and automatically converts it into complete and valid HTML5.

Purpose

  • Automatic conversion of JML to HTML5
  • Reduction of code compared to manual HTML

JML Documentation

Main Classes of Ascoos OS

  • THTML : JML parser + HTML generator
  • TFilesHandler : Secure writing of the generated HTML to a file

File Structure

The implementation is contained in a single PHP file: - jml_to_html_renderer.php

It includes all the logic: interpreting JML, converting to HTML, and saving to an HTML file.

Prerequisites

  1. PHP ? 8.2
  2. Installed Ascoos OS or AWES 26

Execution Flow

  1. Configure operational properties.
  2. Initialize the classes.
  3. Declare the `JML` string.
  4. Parse the JML string into HTML.
  5. Manually add the DOCTYPE.
  6. Save the generated HTML to a file.
  7. Display the generated HTML code.
  8. Release resources and handlers.

Code Example

html:lang('en') {
  head {
    title {`Untitled-1`}
    meta:charset('utf-8')
    meta:name('description'),content('')
    link:rel('icon'),type('image/x-icon'),href('./favicon.ico')
  }
  body {
    h1{`Hello JML World`}
  }
}

Expected Result

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Untitled-1</title>
    <meta name="description" content="">
    <link rel="icon" type="image/x-icon" href="./favicon.ico">
</head>
<body>
    <h1>Hello JML World</h1>
</body>
</html>

Resources

License

This study is covered by the Ascoos General License (AGL). See LICENSE.md.


  Files folder image Files (6)  
File Role Description
Accessible without login Plain text file jml_to_html_renderer-el.md Doc. Auxiliary data
Accessible without login Plain text file jml_to_html_renderer.md Doc. Auxiliary data
Accessible without login Plain text file jml_to_html_renderer.php Example Example script
Accessible without login Plain text file LICENSE-GR.md Lic. License text
Accessible without login Plain text file LICENSE.md Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
Downloadjml-to-html-renderer-2025-12-18.zip
Downloadjml-to-html-renderer-2025-12-18.tar.gz
Install with ComposerInstall with Composer
Needed packages  
Class DownloadWhy it is needed Dependency
Ascoos OS Download .zip .tar.gz Uses Ascoos OS Classes Required
 Version Control Unique User Downloads  
 100%
Total:0
This week:0