Add formatting markup to comments in a playground page. Add headings, bold, italic, and bullets to a document.
- [Instructor] So far you've made code in a Playground. But often, you'll want to explain your code to others. Playground has Markup notation to format text in the Playground. Let's start by formulating some text, and learning the basics of Markup. Markup is text characters in a special type of comment that change the appearance of your text. Go to Xcode, and Open the Menu Board file. Select Menu Board. Then you can Close the Navigator, and the Assistant Editor, to give yourself plenty of room.
At the top of the code, you'll notice two comments you added when you created the file. A comment followed with a colon tells Playgrounds this is Markup. The hash mark makes this a header one. Nothing after the colon, makes this a paragraph text. Let's add two lines of text. Below import PlaygroundSupport, add this. //: Introduction.
//: MenuBoard is part one of this proposal for the Huli Pizza Company Menu System. The menu board is a static page which the restaurant uses on displays to show menu items to customers in-store.
Let's see what this looks like. In Xcode's drop-down menus click Editor. And then Show Rendered Markup. The comments changed to formatted text. You can't change this text in rendered mode. In the Editor Drop-down, change back to Show Raw Markup. The lines above are a single line of text. You can add a block of Markup text using the block comments, and a colon. Add a /*:, and then two lines underneath that, */ to the code, and give yourself a little space.
Start your text the line after the Markup blocks start. Anything on the markup block start line, will be invisible. Add the following in the block. Features. Menu Board is full of features: An image of a pizza. An adaptable layout which sizes to the display.
Easily changeable prices and menu items. Fun, warm font that has a chalkboard feel. Check your work by Showing the Rendered Markup. You get a paragraph. Go back to the Raw Text. A single hash mark is a heading one, like we have at top.
Two hash marks is heading two, and three hash marks are heading three. Put Two Hash Marks in a space in front of Introduction. Put Three Hash Marks in a space in front of Features, making sure you start it in the very first column of the line. Go ahead and take a look at your work. The top has a heading one, introduction is heading two, and features heading three.
Show Raw Markup again. The asterisk is a heavily used character for Markup. Use it for italics with one, beginning and ending selecting text. Add an asterisk before and after Huli Pizza Company. Add two asterisks before and after the two places Menu Board appears. Two asterisks make the selected text bold.
As you type Markup, put the Markup in the first text column to make absolutely sure Markup catches your command. A space will make it ignore it. To not mix up with bold and italic, there are also pluses and dashes at the beginning of a line for a bullet. Put a plus in front of the items on the features list. Show the Markup, and you get bullets. Menu board is in bold, Huli Pizza Company is in italics, and there's our bullets for the menu board.
With this Markup, you can format your text in a Playground code to be more readable, and express your idea much more significantly than you can with mere comments. Markup can be pretty tricky though. Make sure you put the markup indicators in the right place, otherwise Playgrounds will think it's a simple character.
- Comparing iPad and Xcode playgrounds
- Creating and testing Swift classes and code in iPad and Xcode playgrounds
- Prototyping code
- Debugging and testing with Quick Look live views
- Using markup to interactively document code and create educational lessons
- Compiling code into playground books