Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I edit a Markdown file in Xcode?

Tags:

xcode

markdown

I can't figure out how can I edit a Markdown file in Xcode. The file appears to be rendered in a read only mode. Is there any setting that allows me to edit Markdown files in Xcode?

I'm trying to add note to apple's sample project's README.md https://developer.apple.com/documentation/pencilkit/drawing_with_pencilkit

Screenshot of a Markdown file opened in Xcode

like image 837
Legolas Wang Avatar asked May 04 '20 01:05

Legolas Wang


People also ask

How do I edit a Markdown file?

How to edit a README.md file: Open the project editor and make sure that the README.md file is selected in the file view on the left. At the top of the editing pane, click the EDIT MARKDOWN button to reveal edit mode for the file. Now you can start typing directly in the file.

Does Xcode support Markdown?

plist is what triggers Xcode to render the Markdown as seen in their sample. This file can be found under the . xcodeproj (within Package Contents). It seems Apple intended for Markdown files to be rendered only if they are under a sample project.

How do I view MD files in Xcode?

Open your . md file. Go to right navigation pane and select "Show the File inspector"

How do I open a Markdown file on a Mac?

MAC users can also use Apple TextEdit to open MD files. This free text editor has some very handy features, such as a built-in spell-checker, table, and list formatting options and the ability to import graphics.

How do I use Markdown in VS Code?

VS Code supports Markdown files out of the box. You just start writing Markdown text, save the file with the .md extension and then you can toggle the visualization of the editor between the code and the preview of the Markdown file; obviously, you can also open an existing Markdown file and start working with it.

How do I convert a markdown file to HTML?

Create a Markdown file using a text editor or a dedicated Markdown application. The file should have an .md or .markdown extension. Open the Markdown file in a Markdown application. Use the Markdown application to convert the Markdown file to an HTML document.

How do I open the editor in the Markdown preview?

The currently selected line in the editor is indicated in the Markdown preview by a light gray bar in the left margin: Additionally, double clicking an element in the Markdown preview will automatically open the editor for the file and scroll to the line nearest the clicked element.

How do I open a markdown file in word?

Here is an example with a very simple file. Tip: You can also right-click on the editor Tab and select Open Preview ( Ctrl+Shift+V) or use the Command Palette ( Ctrl+Shift+P) to run the Markdown: Open Preview to the Side command ( Ctrl+K V ).


3 Answers

If your .md file is uneditable, you're likely not in Source Code mode. Right click on the file in the Project navigator (the left panel on your screenshot, if it's not visible, press Cmd+1) and select Open As/Source Code.

Screenshot of the context menu

If you want to edit .md files in an Xcode project downloaded from the Apple Developer site, delete these two files in the project folder before opening the project:

Configuration/SampleCode.xcconfig
[project name].xcodeproj/.xcodesamplecode.plist

Here's how too access the second file:

  • Right-click on the .xcodeproj file in Finder and select Show Package Contents.
  • If hidden files are not visible in Finder, press ⌘⇧. (Cmd+Shift+period).
like image 193
Tamás Sengel Avatar answered Oct 19 '22 10:10

Tamás Sengel


For xcode 12:

Right inspector panel, change Type to be: swift source

Close editor

Right click file, 'open as source code' again

like image 40
CodeFarmer Avatar answered Oct 19 '22 09:10

CodeFarmer


As of Xcode 13.2.1 this is still broken. Here's an ugly workaround:

  1. Create a file in your Project.xcodeproj/ directory named .xcodesamplecode.plist and copy into it the following content:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array/>
</plist>
  1. Step 1 will cause Xcode to render README.md as markdown in read-only mode.

  2. To edit the markdown, close all windows and/or tabs in which README.md is visible.

  3. Rename README.md to anything else with a .md suffix, for example editable.md.

  4. Now open editable.md and it will be editable.

  5. When finished editing close all editable.md windows and rename it back to README.md.

  6. File a bug report with Apple.

like image 1
par Avatar answered Oct 19 '22 10:10

par