Effective blog Writing

76 views Asked by At

whenever I copy the contents of Visual Studio 2010 to my blog, it appears as a normal black font, with the formatting and color of the C# code not applying to my Google blogger. How do I fix this problem?

Here's an example of my code:

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace BookStore.Models
{
    public class Book
    {
        [Key]
        public int Id { get; set; }
        [Required]
        [MaxLength(30)]
        public string Title { get; set; }
        public string Authers { get; set; }

        [Column("Year")]
        [Display(Name = "Publish Year")]
        public string publishYear { get; set; }

        [Column("Price")]
        [Display(Name = "Price")]
        public decimal BasePrice { get; set; }
    }
} 

I want this to be highlighted as C# code.

2

There are 2 answers

0
CinCout On BEST ANSWER

I have tried the following with another platform but not with Blogger. I am not sure whether it will serve your purpose. But it is definitely worth a try:

  1. Copy and paste from Visual Studio into a Word document.
  2. Copy and paste from the Word document into the rich text editing field of the blog.

Copy and paste directly from Visual Studio into the rich text editing field will not preserve the syntax highlighting. I have no clue why.

0
GoBusto On

The coloration of program code is known as Syntax Highlighting, and is not something that Blogger supports by default - try searching for a syntax highlighting add-on/plug-in for Blogger, and see what you find.

We use a combination of Markdown and highlight.js for our code documentation at work. I'm not sure if this can be used with Blogger, but it might be an option if you host your blog elsewhere.