Skip to content

Commit

Permalink
feat: add html code.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Jun 18, 2022
1 parent 1b009fd commit 40d9efa
Show file tree
Hide file tree
Showing 5 changed files with 281 additions and 64 deletions.
125 changes: 97 additions & 28 deletions src/go.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,115 @@

const code = `// Prime Sieve in Go.
// Taken from the Go specification.
// Copyright © The Go Authors.
const code = `// We often need our programs to perform operations on
// collections of data, like selecting all items that
// satisfy a given predicate or mapping all items to a new
// collection with a custom function.
// In some languages it's idiomatic to use [generic](http://en.wikipedia.org/wiki/Generic_programming)
// data structures and algorithms. Go does not support
// generics; in Go it's common to provide collection
// functions if and when they are specifically needed for
// your program and data types.
// Here are some example collection functions for slices
// of \`strings\`. You can use these examples to build your
// own functions. Note that in some cases it may be
// clearest to just inline the collection-manipulating
// code directly, instead of creating and calling a
// helper function.
package main
import "strings"
import "fmt"
// Send the sequence 2, 3, 4, ... to channel 'ch'.
func generate(ch chan<- int) {
for i := 2; ; i++ {
ch <- i // Send 'i' to channel 'ch'
}
// Returns the first index of the target string \`t\`, or
// -1 if no match is found.
func Index(vs []string, t string) int {
for i, v := range vs {
if v == t {
return i
}
}
return -1
}
// Returns \`true\` if the target string t is in the
// slice.
func Include(vs []string, t string) bool {
return Index(vs, t) >= 0
}
// Copy the values from channel 'src' to channel 'dst',
// removing those divisible by 'prime'.
func filter(src <-chan int, dst chan<- int, prime int) {
for i := range src { // Loop over values received from 'src'.
if i%prime != 0 {
dst <- i // Send 'i' to channel 'dst'.
// Returns \`true\` if one of the strings in the slice
// satisfies the predicate \`f\`.
func Any(vs []string, f func(string) bool) bool {
for _, v := range vs {
if f(v) {
return true
}
}
}
return false
}
// The prime sieve: Daisy-chain filter processes together.
func sieve() {
ch := make(chan int) // Create a new channel.
go generate(ch) // Start generate() as a subprocess.
for {
prime := <-ch
fmt.Print(prime, "\\n")
ch1 := make(chan int)
go filter(ch, ch1, prime)
ch = ch1
}
// Returns \`true\` if all of the strings in the slice
// satisfy the predicate \`f\`.
func All(vs []string, f func(string) bool) bool {
for _, v := range vs {
if !f(v) {
return false
}
}
return true
}
func main() {
sieve()
// Returns a new slice containing all strings in the
// slice that satisfy the predicate \`f\`.
func Filter(vs []string, f func(string) bool) []string {
vsf := make([]string, 0)
for _, v := range vs {
if f(v) {
vsf = append(vsf, v)
}
}
return vsf
}
// Returns a new slice containing the results of applying
// the function \`f\` to each string in the original slice.
func Map(vs []string, f func(string) string) []string {
vsm := make([]string, len(vs))
for i, v := range vs {
vsm[i] = f(v)
}
return vsm
}
func main() {
// Here we try out our various collection functions.
var strs = []string{"peach", "apple", "pear", "plum"}
fmt.Println(Index(strs, "pear"))
fmt.Println(Include(strs, "grape"))
fmt.Println(Any(strs, func(v string) bool {
return strings.HasPrefix(v, "p")
}))
fmt.Println(All(strs, func(v string) bool {
return strings.HasPrefix(v, "p")
}))
fmt.Println(Filter(strs, func(v string) bool {
return strings.Contains(v, "e")
}))
// The above examples all used anonymous functions,
// but you can also use named functions of the correct
// type.
fmt.Println(Map(strs, strings.ToUpper))
}
`;

export default code;
103 changes: 103 additions & 0 deletions src/html.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
const code = `<!DOCTYPE HTML>
<!--Example of comments in HTML-->
<html>
<head>
<!--This is the head section-->
<title>HTML Sample</title>
<meta charset="utf-8">
<!--This is the style tag to set style on elements-->
<style type="text/css">
h1
{
font-family: Tahoma;
font-size: 40px;
font-weight: normal;
margin: 50px;
color: #a0a0a0;
}
h2
{
font-family: Tahoma;
font-size: 30px;
font-weight: normal;
margin: 50px;
color: #fff;
}
p
{
font-family: Tahoma;
font-size: 17px;
font-weight: normal;
margin: 0px 200px;
color: #fff;
}
div.Center
{
text-align: center;
}
div.Blue
{
padding: 50px;
background-color: #7bd2ff;
}
button.Gray
{
font-family: Tahoma;
font-size: 17px;
font-weight: normal;
margin-top: 100px;
padding: 10px 50px;
background-color: #727272;
color: #fff;
outline: 0;
border: none;
cursor: pointer;
}
button.Gray:hover
{
background-color: #898888;
}
button.Gray:active
{
background-color: #636161;
}
</style>
<!--This is the script tag-->
<script type="text/javascript">
function ButtonClick(){
// Example of comments in JavaScript
window.alert("I'm an alert sample!");
}
</script>
</head>
<body>
<!--This is the body section-->
<div class="Center">
<h1>NAME OF SITE</h1>
</div>
<div class="Center Blue">
<h2>I'm h2 Header! Edit me in &lt;h2&gt;</h2>
<p>
I'm a paragraph! Edit me in &lt;p&gt;
to add your own content and make changes to the style and font.
It's easy! Just change the text between &lt;p&gt; ... &lt;/p&gt; and change the style in &lt;style&gt;.
You can make it as long as you wish. The browser will automatically wrap the lines to accommodate the
size of the browser window.
</p>
<button class="Gray" onclick="ButtonClick()">Click Me!</button>
</div>
</body>
</html>
`;

export default code;
26 changes: 16 additions & 10 deletions src/ini.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@

const code = `; last modified 1 April 2001 by John Doe
[owner]
name=John Doe
organization=Acme Widgets Inc.
[database]
; use IP address in case network name resolution is not working
server=192.0.2.62
port=143
file="payroll.dat"
const code = `# Example of a .gitconfig file
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
hideDotFiles = dotGitOnly
# Defines the master branch
[branch "master"]
remote = origin
merge = refs/heads/master
`;

export default code;
65 changes: 51 additions & 14 deletions src/sql.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,56 @@

const code = `-- SQL Mode for CodeMirror
SELECT SQL_NO_CACHE DISTINCT
@var1 AS \`val1\`, @'val2', @global.'sql_mode',
1.1 AS \`float_val\`, .14 AS \`another_float\`, 0.09e3 AS \`int_with_esp\`,
0xFA5 AS \`hex\`, x'fa5' AS \`hex2\`, 0b101 AS \`bin\`, b'101' AS \`bin2\`,
DATE '1994-01-01' AS \`sql_date\`, { T "1994-01-01" } AS \`odbc_date\`,
'my string', _utf8'your string', N'her string',
TRUE, FALSE, UNKNOWN
FROM DUAL
-- space needed after '--'
# 1 line comment
/* multiline
comment! */
LIMIT 1 OFFSET 0;
const code = `CREATE TABLE dbo.EmployeePhoto
(
EmployeeId INT NOT NULL PRIMARY KEY,
Photo VARBINARY(MAX) FILESTREAM NULL,
MyRowGuidColumn UNIQUEIDENTIFIER NOT NULL ROWGUIDCOL
UNIQUE DEFAULT NEWID()
);
GO
/*
text_of_comment
/* nested comment */
*/
-- line comment
CREATE NONCLUSTERED INDEX IX_WorkOrder_ProductID
ON Production.WorkOrder(ProductID)
WITH (FILLFACTOR = 80,
PAD_INDEX = ON,
DROP_EXISTING = ON);
GO
WHILE (SELECT AVG(ListPrice) FROM Production.Product) < $300
BEGIN
UPDATE Production.Product
SET ListPrice = ListPrice * 2
SELECT MAX(ListPrice) FROM Production.Product
IF (SELECT MAX(ListPrice) FROM Production.Product) > $500
BREAK
ELSE
CONTINUE
END
PRINT 'Too much for the market to bear';
MERGE INTO Sales.SalesReason AS [Target]
USING (VALUES ('Recommendation','Other'), ('Review', 'Marketing'), ('Internet', 'Promotion'))
AS [Source] ([NewName], NewReasonType)
ON [Target].[Name] = [Source].[NewName]
WHEN MATCHED
THEN UPDATE SET ReasonType = [Source].NewReasonType
WHEN NOT MATCHED BY TARGET
THEN INSERT ([Name], ReasonType) VALUES ([NewName], NewReasonType)
OUTPUT $action INTO @SummaryOfChanges;
SELECT ProductID, OrderQty, SUM(LineTotal) AS Total
FROM Sales.SalesOrderDetail
WHERE UnitPrice < $5.00
GROUP BY ProductID, OrderQty
ORDER BY ProductID, OrderQty
OPTION (HASH GROUP, FAST 10);
`;

export default code;
26 changes: 14 additions & 12 deletions src/xml.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@

const code = `<html style="color: green">
<!-- this is a comment -->
<head>
<title>HTML Example</title>
</head>
<body>
The indentation tries to be <em>somewhat &quot;do what
I mean&quot;</em>... but might not match your style.
</body>
</html>
`;
const code = `<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
<add name="MyDB"
connectionString="value for the deployed Web.config file"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
<system.web>
<customErrors defaultRedirect="GenericError.htm"
mode="RemoteOnly" xdt:Transform="Replace">
<error statusCode="500" redirect="InternalError.htm"/>
</customErrors>
</system.web>
</configuration>`;

export default code;

0 comments on commit 40d9efa

Please sign in to comment.