Ask Question
22 August, 15:56

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. 22 August, 16:40
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers