Ask Question
12 November, 01:37

Let's write a simple markdown parser function that will take in a single line of markdown and be translated into the appropriate HTML.

+5
Answers (1)
  1. 12 November, 02:01
    0
    Here is the answer in Java with appropriate comments for understanding

    Explanation:

    import java. util. Scanner;

    public class Hash {

    public static void main (String[] args) {

    System. out. print ("Enter a string : ");

    Scanner scanner = new Scanner (System. in);

    String s = scanner. nextLine (); / /read string

    int k=s. lastIndexOf ('#'), count=0; //find last occurence of # then take the next part

    String s2="", s3="";

    for (int i=0; i
    {

    if (s. charAt (i) = ='#')

    count++; //count the occurence of # of level of heading h1, h2, h3, ...

    }

    for (int j=k+1; j
    {

    s2+=s. charAt (j); //take the remainging string after #

    }

    / / System. out. println (k);

    //System. out. println (count);

    if (count<=6) / /if it is valid heading

    {

    s3=""+s2+"";

    System. out. println (s3);

    }

    else

    System. out. println ("Invalid header");

    }

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Let's write a simple markdown parser function that will take in a single line of markdown and be translated into the appropriate HTML. ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers