Add front matter to markdown in Node - node.js

I am trying to generate .md files by Nodejs, and the file should contain the front matter.
This is what I am doing:
let {title,date,markdown_content}=document;
let fileContent = `
---
title: '${title}'
date: ${date}
---
${markdown_content}
`;
Now the title may contain special characters like " ' and etc(find more in this post).
Any nodejs library can be used out of box to do this job? Or I will have to replace the characters manually.

Related

Appending a tag at targeted place

strong text
I have following output
I want to add tags before and after "reporting formalities"
I also want to add tags before means and after the full stop . or semi ;
finally export the appended file
I have This file name is: /content/data/32010L0065.xml
tag name: heading
text name: Definitions
tail name:
/tMy next sibling is: {http://docs.oasis-open.org/legaldocml/ns/xml/3.0}list
"reporting formalities" means the information set out in the Annex which;
"electronic transmission of data" means the process of transmitting information that has been encoded digitally, using a revisable.
file_content = open ('.akn_file', 'a+')
file_content.write
file_content.close()

Robot Framework : How to remove all spaces after the string

I am new to robot framework.
I want to know how can i remove all white spaces after the string .
My string is "OTP Hello
"
I want all spaces and line break after Hello to get deleted
How can I achieve it?
Use the Strip String keyword in the Strings library, and specify mode=right, to remove the whitespace only from the right side. Sample:
${src}= Set Variable OTP Hello${SPACE}\n
Log To Console The source: ---${src}---
${stripped}= Strip String ${src} mode=right
Log To Console The result: ---${stripped}---
The output will be:
The source: ---OTP Hello
---
The result: ---OTP Hello---

How would I isolate a string between two strings in DiscordJS?

I've currently been using this script:
var portion = body.substring(
str.lastIndexOf('ID Background',") + 1,
str.lastIndexOf('ID Theme',")
);
"Body" is the input, "Portion" being the output.
I'm trying to isolate text between the words strings "ID Background" and "ID Theme"
Example:
ID Background
Background information Background information Background information Background information
ID Theme
Theme information Theme information Theme information Theme information Theme information
...Et Cetera.
Expected Output:
Background information Background information Background information
Current Output:
undefined
I cannot figure out why this script is not working. I'm using this for a Discord bot (Discord.JS)
You should use RegExp capturing groups ()
// objective: get everything in between 'start' and 'end'
const str = 'start hello how was your day end';
// capture everything in between the two words in parentheses
console.log(str.match(/start (.*) end/)[1]);
Since you're example uses line breaks, which the special character . doesn't cover, you should use [\s\S] (\s is whitespace, and \S is anything but whitespace. Together, they cover everything. Also, use optional chaining ? so that your code doesn't throw a TypeError if no match is found.
var portion = body.match(/ID Background *([\s\S]*) *ID Theme/)?.[1];
if (!portion)
// no match found...

Long strings within variables in jade

I am writing a web application that supports multiple languages. What I am doing is passing strings to a translator class and it will perform the translation. Now I need to add some long text in my templates and I would like to have it on multiple lines for readability.
- var longText = 'Some really long text ... ';
// ...
p #{i18n.tr(longText)}
I would like to do something like
- var longText = 'Some text ' +
- 'some other text'
// ...
p #{i18n.tr(longText)}
Unfortunatly jade does not like that.
Is it possible to have strings on multiple lines in jade?
According to this forum, it is undocumented but ending a line in a backslash allows a string to continue onto the next line.
https://github.com/jadejs/jade/issues/1447

Any way to figure out what language a certain file is in?

If I have an arbitrary file sent to me, using Node.js, how can I figure out what language it's in? It could be a PHP file, HTML, HTML with JavaScript inline, JavaScript, C++ and so on. Given that each of these languages is unique, but shares some syntax with other languages.
Are there any packages or concepts available to figure out what programming language a particular file is written in?
You'd need to get the extension of the file. Are you getting this file with the name including the extension or just the raw file? There is no way to tell if you do not either get the file name with the extension or to scan the dir it's uploaded to and grabbing the names of the files, and performing a directory listing task to loop through them all. Node has file system abilities so both options work. You need the file's name with extension saved in a variable or array to perform this. Depending on how you handle this you can build an array of file types by extensions optionally you can try using this node.js mime
Example:
var fileExtenstions = {h : "C/C++ header", php : "PHP file", jar : "Java executeable"};
You can either split the string that contains the files name using split() or indexOf() with substring.
Split Example:
var fileName = "hey.h"; // C/C++/OBJ-C header
var fileParts = fileName.split(".");
// result would be...
// fileParts[0] = "hey";
// fileParts[1] = "h";
Now you can loop the array of extensions to see what it is and return the description of the file you set in the object literal you can use a 2d array and a for loop on the numeric index and check the first index to see it's the extension and return the second index(second index is 1)
indexOf Example:
var fileName = "hey.h";
var delimiter = ".";
var extension = fileName.substring( indexOf( delimiter ), fileName.length );
now loop through the object and compare the value

Resources