How to display XAML source code on WordPress without any plugins


I have displayed some source code in the previous post, ListView(1), but it was a little bit difficult to display XAML source code especially in WordPress.  I tried to copy and paste them from Visual Studio to WordPress visual editor, and also to try the script, <pre><code> source code </code></pre> in WordPress html editor.  But the behavior of the source code display is unstable pretty much when switching visual/html editor.  The reason seems to be the characters, "<" and ">" etc., in XAML source code, which should be escaped in html.  The character string for comment-out, "<!-- -->", also seems to be causing the unstableness.  It may be a problem specific to WordPress (not so unstable in Blogger).  Besides, someone says that the posted article is correctly displayed, even though the display of source code is collapsed in the visual editor.

So, trying out various methods without any plugins and any other complicated tools, it seems to be relatively easy to do as follows:

In WordPress html editor on Mac, copy and paste the script below.

html script to display XAML source code
<div style="padding: 5px 10px; width: 200px; color: white; background: black; border: 1px solid black;">ファイル名</div>
<div style="background: white; overflow: auto; width: 630px; border: 1px solid green; height: 270px; padding: 10px; white-space: nowrap;">
Source Code
Source Code
Source Code
Source Code  ( Actually, this html script is being displayed by this script. )
</div>


Copy and paste XAML source code from the editor of Visual Studio for Mac to the place of "source code" in this script and post it, XAML source code is beautifully displayed as follows!

MainPage.xaml
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
            xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
            x:Class="ListView.MainPage">
        <ContentPage.Content>
        <StackLayout>


            <!-- Add a new book to the book list "BookListView" -->
            <Button Text="Add New Book" Clicked="OnNewBook" />
            <Entry x:Name="Entry1" Placeholder="Input New BookKeyboard="Text" />


            <!-- Create a book List "BookListView".
                 Call "OnTap" method, if one of the books is tapped -->
            <ListView x:Name="BookListView" ItemTapped="OnTap" >
                    </ListView>


        </StackLayout>
        </ContentPage.Content>
</ContentPage>


I wanted to add line numbers to the source code above, but it was quite difficult by simple html code.  So, I will write posts using the script above.

コメント

このブログの人気の投稿

Get the Color Code from an Image Pixel

PCL Storage (1)

Prolog Interpreter