CoderLegion has an article editor that can format text. We will see the editor when we press the Post An Article button. In this article, we will talk about how to format text or code using the code formatter button and see how it looks like when html is finally rendered.
1. How it is done in coderlegion editor #
From the coderlegion editor, follow the following steps.
- Paste code
- Select the code
- Press the {} button in the code editor. See image 1.
Image 1

"""Python module docstring
"""
class Study:
def __init__(self, name):
self.name = name
def get_name(self):
"""Get name"""
return self.name
# Declare name
name = 'Peter'
mystrlist = ['USA', 'Algeria']
mynumlist = [4, 8, 6]
myfloatlist = [25.2, 8.6, 58.5]
mydict = {'job': 'programmer', 'age': 45}
mytuple = (5, 'island')
a = Study(name) # instantiate class
# Print name.
print(a.get_name())
// Modify gre value.
document.getElementById("gre").innerHTML = "World Cup";
class Car {
constructor(name, age) {
this.name = name;
this.age= age;
}
}
/*
Multi-line comment.
Define a new Car.
*/
let myCar1 = new Car("Acura", 2);
const cars = ["toyota", "Bentley", "audi"];
let x = 100 + 50;
let mycomment = "The covid-19 variants.";
let pattern = /[^h]/g;
function get_system(param_x, param_y) {
return param_x + param_y;
}
variables / strings
<?php
$color = "blue";
echo "My shirt is " . $color . "<br>";
?>
function
<?php
function welcome_message() {
echo "Hello world!";
}
welcome_message(); // call the function
?>
class
<?php
class Building {
// Properties
public $name;
public $color;
// Methods
function set_name($name) {
$this->name = $name;
}
function get_name() {
return $this->name;
}
}
?>
comments / variables
#include <iostream>
using namespace std;
int main() {
// This is a comment
int num_experience = 10;
cout << num_experience;
/* The code below will print the words Hello World!
to the screen, and it is amazing */
cout << "Hello World!";
return 0;
}
class
#include <string>
#include <iostream>
using namespace std;
class MyClass {
public:
int num;
string my_str;
};
int main() {
MyClass sample; // Create an object of MyClass
// Access attributes and set values
sample.num = 15;
sample.my_str = "Some text";
// Print attribute values
cout << sample.num << "\n";
cout << sample.my_str;
return 0;
}
preprocessor
#include <iostream>
using namespace std;
#define PI 3.14159
#define MIN(a,b) (((a)<(b)) ? a : b)
#ifndef NULL
#define NULL 0
#endif
int main () {
cout << "Value of PI :" << PI << endl;
cout << MIN(2, 6) << endl;
return 0;
}
{
"fruit": "Apple",
"size": 45,
"invoiceTime": "2018-12-10T13:49:51.141Z",
"total": 336.36,
"q1": {
"question": "5 + 7 = ?",
"options": [
"10",
"11",
"12",
"13"
],
"answer": "12"
}
}
@import url("./border.css");
@import url("./font.css");
#box {
width: 200px;
height: 200px;
background-color: rgb(14, 179, 142);
}
.center {
text-align: center;
color: red;
}
/* This is
a multi-line
comment */
p {
background-color: red !important;
}
@font-face {
font-family: 'Helvetica';
src: url('Helvetica') format('woff'),
local('Helvetica.woff') format('woff');
}
/* This is a single-line comment */
a[target=_blank] {
background-color: yellow; /* Set text color to red */
}
<!--Tallest buildings-->
<buildings>
<rank id="1">
<name>Burj Khalifa</name>
<city>Dubai</city>
</rank>
<rank id="2">
<name>Merdeka 118</name>
<city>Kuala Lumpur</city>
</rank>
</buildings>
/**
* javadoc: main class.
*/
public class Main {
public static void main(String[] args) {
// This is a comment.
System.out.println("Hello Mars");
/* Multi-line
comment
*/
System.out.println("Hello Earth"); // Earth
int num_ships = 100;
String ship_name = "Lantern";
}
}
using System;
namespace coderlegion
{
class Program
{
// main
static void Main(string[] args)
{
/*
multi-line
comment
*/
Console.WriteLine("Hello Coderlegion !"); // world
}
}
}
use Config; #config
my $secure_perl_path = $Config{perlpath};
sub foo ($left, $right) {
return $left + $right;
}
=begin
multi-line
comment
=cut
if ($^O ne 'VMS') {
$secure_perl_path .= $Config{_exe}
#single line comment
unless $secure_perl_path =~ m/$Config{_exe}$/i;
}
function
def sayGoodnight(name)
result = "Goodnight, " + name
return result
end
# Time for bed...
puts sayGoodnight("John-Boy")
puts sayGoodnight("Mary-Ellen")
class
=begin
multi-line
comment
=end
class Song
def initialize(name, artist, duration)
@name = name
@artist = artist
@duration = duration
end
end
CREATE TABLE Country (
CountryID int,
Name varchar(255),
Population int
);
SELECT * FROM Orders WHERE OrderDate='2022-12-11'
; comment
[Section-name]
key=value
myoption=true # in-line comment
number1=123
sample_float=123.12
; boolean true/false
beautiful=true
dangerous=false
variable
#!/bin/bash
# variable example
sports1=football
sports2=basketball
echo $sports1 $sports2
keyword
#!/bin/bash
echo "Input a directory name"
read new_dir
`mkdir $new_dir`