First Steps Toward learning Modern Digital Practices for Sustainable and Shareable Research
Tuesday January 26, 2018, 12:30-3:30pm PST
UCSB South Hall 2509
markdownlint
extension for VS Code.Documents should be created to conform to the following ideals:
Simplicity is about ease of production—and reproduction.
Markup symbols should describe content or style (but not both).
Clarity is about ease of reading.
Standards are about best practices for simplicity and clarity, as well as for easy conversion between formats. Document format, structure, and styling should
These are principles, not rules.
In some contexts, there are good reasons to set them aside.
These, and similar types of markup are intended to produce “rich” documents, so they contain vocabularies that risk violating the principles of simplicty and clarity.
Markdown is a plain text format for writing structured documents. Instead of tags, it uses symbols that were conventional in the early days of email before we had rich text editors.
Increasingly, developers are producing tools that support Markdown (including reveal.js
, which was used to produce this slideshow).
People are also using Markdown for general writing because of its ease of use, because it enforces principles of simplicity and clarity, and because it is easy to convert to multiple formats.
Can’t I just use Word? I know how to use that.
Even if you know how to use Word well, do you?
Do you really?
Word hides its (proprietary) markup, which encourages users to be sloppy. As long as it looks all right, who cares?
Word’s powerful features tempt users to violate the principles and best practices enforced by Markdown.
Word would be better if there were a tool to check documents against a schema that describes what a good document should look like. This process is known as “validation”.
There are good reasons for using Word in some contexts, but give Markdown a try, and you'll find yourself using Word less and less.
.md
.A linter is any tool that detects and flags errors in programming languages, including stylistic errors...For example, modern lint checkers are often used to find code that does not correspond to certain style guidelines.
Linting our Markdown (or any other code) is one way that we can ensure that it is well-formed according to the standards of the markup language and valid according to a schema that describes our style practices.
Most online Markdown editors will not correctly render Markdown as HTML if they are not well-formed, but they don’t always tell you what is wrong. A good linting tool will do this.
A linter for bibliographical citation would be the Holy Grail.
#sigh
A standard known as CommonMark is nearing completion. It is the basis for GitHub-Flavored Markdown, which has some additional extensions used for rendering Markdown on GitHub.
WE1S uses GitHub-Flavored Markdown for all project documents.
More tools are available on the workshop website.
Enter
.Online tools are for quick jobs. In a realistic working scenario, it is better to author Markdown documents in a code editor.
VS Code provides both code linting and HTML preview for Markdown documents.
myfile.md
will also switch the language to Markdown.Ctrl+Shift+V
to open a preview. in a new tab. You can view the preview side-by-side (Ctrl+K V
) with the file you are editing and see changes reflected in real-time as you edit.Important: some errors indicate that your code is not well-formed according to the Markdown specification. Other errors are stylistic rules established by the author of the linter extension. The latter are subjective. If you want to turn off individual rules, there are instructions in the markdownlint
GitHub repo.
You can use HTML and CSS in Markdown documents to achieves effects not possible in pure Markdown. Whilst this defeats the purpose of Markdown, there are cases when it is worth it.
Try typing the following into VS Code:
<b style="color: red;">Some text</b>
How does it display in the preview? Is it acceptable to the linter?
A single line break is treated as a space. To force a line break, place two spaces or a “\
” at the end of the line.
Try this in VS Code and see what the linting rule is.
Try typing **some text**
in VS Code. Notice that it renders as some text in the preview?
But what if you want the asterisks?
For this you will need to “escape” them with backslashes. Type the following in VS Code:
\*\*some text\*\*
Notice the difference? This works with any Markdown formatting character.
In HTML, entity representations like þ
and þ
can be used for special characters (both these examples produce þ).
All valid HTML entities are also valid in Markdown.
It is possible to format complex tables in Markdown, but they are challenging to get right. You can use the Markdown Table Generator to help you out. Table-Magic is also useful for converting to and from CSV format.
Large data tables are not recommended for Markdown documents.
Inline code is normally represented by back ticks (`). For instance,
`let x = 3;`
will display with “syntax highlighting”.
If your code includes back ticks, you can use two back ticks to enclose the code.
Code blocks are represented by three back ticks on the line before and after the code snippet. After the first set of back ticks the name of the coding language should be used, e.g.
```javascript
let x = 3;
```
Some implementations extend the standard. Two useful extensions used on GitHub are “strikethrough” and “task lists”.
Strikethrough is formatted with two tildes: ~~delete this~~
will render as delete this.
Task lists are check boxes:
- [ ] Uncompleted task
- [x] Completed task
produces
Task lists are only guaranteed to render on GitHub.
You can’t link to an external tab in Markdown. Instead, use inline HTML:
<a href="http://we1s.ucsb.edu" target="_blank">WE1S Website</a>
Be careful when using emphasis on links. Placing the formatting markup outside the brackets is well-formed:
_[My label](http://we1s.ucsb.edu)_
It is not possible to control the size or alignment with Markdown. Use inline HTML if this is necessary.
git
+ cloud storage + social media = Octocat
git
?Git
is a version control system for tracking changes in computer files and coordinating work on those files among multiple people. It is primarily used for source code management in software development, but it can be used to keep track of changes in any set of files.
From the git
source code:
The name "git" was given by Linus Torvalds when he wrote the very first version. He described the tool as "the stupid content tracker" and the name as (depending on your way):
- random three-letter combination that is pronounceable, and not
actually used by any common UNIX command. The fact that it is a
mispronunciation of "get" may or may not be relevant.
- stupid. contemptible and despicable. simple. Take your pick from
the dictionary of slang.
- "global information tracker": you're in a good mood, and it
actually works for you. Angels sing, and a light suddenly fills the room.
- "goddamn idiotic truckload of shit": when it breaks
git
git
checks for conflicts in merging content pushed to the repository.git
keeps a complete history of the repo, allowing you to roll it back to an earlier state.GitHub’s 15-minute tryGit tutorial teaches you the command line language but is very good for introducing you to the concepts of git
.
git
git
without entering commands in git
's archane language.git
's version control features. The Programming Historian has a tutorial on using GitHub for academic projects.A repository (repo) is stored on both the local machine and the remote GitHub server.
Initially, users clone repos on GitHub. Thereafter, they pull the latest code to keep up to date.
Users perform updates to the repo through a three step process:
README.md
FileA repository typically has a Markdown file called README.md
in its root folder. This file describes the content of the repository.
On the GitHub website, the README.md
file is automatically rendered on the repo’s web page.
git
commands on the command line. You can do anything, but the git
language is relatively unintuitive.git
functions that modify the remote repo. You cannot push local changes to the server.git
functions, including pulling from and pushing to the remote repo.Some combination is the most likely scenario. You can make small commits with GitHub’s web editor, but you have to pull the changes to your local repo.
The GitHub Desktop Client is better than VS Code if you are creating or moving around folders, images, PDFs, and so on. VS Code is convenient of you are editing Markdown, HTML, or text files.
Occasionally, you will encounter arcane conflicts which can only be solved by running git
from the command line. It is generally necessary to Google solutions to find the appropriate code. Installing the GitHub client will automatically install git
on your computer.
File > Options > Accounts
and login. On the Mac, this is under GitHub Desktop > Preferences
.Git
tab and enter the username and email you used for your GitHub account.Advanced
tab and select VS Code as your external editor.GitHub
inside your Documents
folder. In Windows, this will have the local path C:\Users\YourName\Documents\GitHub
. On the Mac it will be ~/Documents/GitHub/
.There are two easy ways to clone a repo.
Clone or download
button on the GitHub website and select Open in Desktop
.File > Clone repository > URL
. Enter the URL and the local path to your GitHub folder.Try this with the workshop sandbox repo: https://github.com/whatevery1says/workshop-sandbox
.
my_name.md
in VS Code.your_name.md
.Commit to Master
.Push Origin
tab at the top of the screen. Your file will be pushed to the remote repo.Pull Origin
tab at the top of the screen to update your local repository folder with the latest changes.View > SCM
. You can also click the Source Control icon in VS Code's Activity Bar.
Try the exercise in the file resolving-merge-conflicts.md
in the workshop sandbox.
We have only scratched the surface. Here are some useful resources:
Pros:
Cons:
WE1S produces content in the following locations:
Wherever possible, content intended only for website pages and blog posts should be authored offline in Markdown and pasted into the Wordpress text editor (click on the Text tab).
The WE1S website uses the Wordpress Jetpack plugin, which automatically converts Markdown to HTML but saves the original Markdown.
Advantages:
Some content should be archived on GitHub. The best workflow is to push the content to GitHub, copy the Markdown from GitHub, and then paste it into the Wordpress text editor. Updates should be performed on GitHub first and the updated content pasted from there into Wordpress.
Non-textual assets (e.g. images) should be archived on GitHub. The urls used to embed these assets in the web pages should point to the files archived on GitHub, not to the Wordpress media library. The reasoning is that GitHub is a more stable repositor than Wordpress’ media library.
In general, documents should be authored in Markdown, if possible, and then converted to other formats (e.g. Word or PDF).
Documents meant to be readable on the GitHub website should be available in Markdown format. Duplicates in other formats can be stored in the same repo.
More complex resources can be stored as a data package with a manifest.
A manifest is a document describing the contents of a repository.
The GitHub README.md
file is a type of manifest.
Manifests are commonly stored in JSON format. JSON stands for “JavaScript Object Notation” because it is based on the method for storing data in that programming language. The basic format is a keyword-value pair separated by commas and enclosed in curly brackets:
{
"name": "Octocat",
"role": "mascot",
"company": "GitHub"
}
VS Code stores its settings in JSON-formatted manifest files, and you need to edit them to configure VS Code.
JSON is an easy format in which to make mistakes. If errors occur, try entering your code an the online JSON Linter.
README.md
file.datapackage.json
.datapackage.json
file MUST contain name
, title
, and resources
properties.name
PropertyThe value of the name property should be a short url-usable (and preferably human-readable) name of the package. This MUST be lower-case and contain only alphanumeric characters along with “.
”, “_
” or “-
” characters. It will function as a unique identifier and MUST be the same as name of its container folder.
title
PropertyA title or one sentence description of the package.
resources
PropertyA list of paths to all files associated with the data package. The list is enclosed in square brackets, and each resource is "path"
-value pair enclosed in curly brackets.
{
"name": "how-to-work-with-markdown",
"title": "How to Work with Markdown",
"resources": [{
"path": "how-to-work-with-markdown.md"
}]
}
See the WE1S Guidelines For Handling Resources.
Slideshow produced by Scott Kleinman
for the WhatEvery1Says Project.