Using Syntax highlighter for blogger

sapan
This is the sample post for testing the syntax highlighter for my Blog.


I am using https://highlightjs.org/

Embedding ;
1. inserting below snippet in the tag



<link href='https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/vs.min.css' rel='stylesheet'/>
<script src='http://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js'/>




<pre><code class="html">

my code here
</code>
</pre>


At last initialize with


<script>
//script initialisation for 'pre' tags
hljs.initHighlightingOnLoad();

</script></div>



Sample code test:-

package skd.app.androidfeatures.jsonReader;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

import java.io.IOException;
import java.io.InputStream;

import skd.app.androidfeatures.R;

public class JsonReader extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_json_reader);

        TextView textView = (TextView)findViewById(R.id.textView3);

        try {
            textView.setText(loadJSONFromAsset("a.txt"));
        }catch (Exception e)
        {
            e.printStackTrace();
        }

    }


    public String loadJSONFromAsset(String filename) throws Exception {
        String json = null;
        try {
            InputStream is = this.getAssets().open(filename);
            int size = is.available();
            byte[] buffer = new byte[size];
            is.read(buffer);
            is.close();
            json = new String(buffer, "UTF-8");
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
        return json;
    }
}






Tags

Post a Comment

0Comments
Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !