Ask Question
5 October, 09:35

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

+3
Answers (1)
  1. 5 October, 11:22
    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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers