라이브러리

[PHP] CommonMarkNode::appendChild - AST 조작




CommonMarkNode::appendChild

CommonMarkNode::appendChild는 PHP에서 사용할 수 있는 메서드입니다. 이 메서드는 CommonMarkNode 객체의 자식 노드를 추가하는 데 사용됩니다. CommonMark는 마크다운 형식의 문서를 처리하기 위한 라이브러리입니다.

사용법

CommonMarkNode::appendChild 메서드는 다음과 같이 사용할 수 있습니다.

#hostingforum.kr
php

use LeagueCommonMarkNodeNode;

use LeagueCommonMarkNodeDocument;

use LeagueCommonMarkNodeText;

use LeagueCommonMarkNodeParagraph;



$document = new Document();

$paragraph = new Paragraph();

$document->appendChild($paragraph);



$text = new Text('Hello, World!');

$paragraph->appendChild($text);



예제

다음은 CommonMarkNode::appendChild를 사용하여 마크다운 문서를 생성하는 예제입니다.

#hostingforum.kr
php

use LeagueCommonMarkNodeNode;

use LeagueCommonMarkNodeDocument;

use LeagueCommonMarkNodeText;

use LeagueCommonMarkNodeParagraph;

use LeagueCommonMarkNodeHeading;

use LeagueCommonMarkNodeList_;

use LeagueCommonMarkNodeListItem;



$document = new Document();

$document->appendChild(new Heading(1, 'Hello, World!'));



$paragraph = new Paragraph();

$document->appendChild($paragraph);



$text = new Text('This is a paragraph.');

$paragraph->appendChild($text);



$list = new List_();

$document->appendChild($list);



$listItem = new ListItem();

$listItem->appendChild(new Text('Item 1'));

$list->appendChild($listItem);



$listItem = new ListItem();

$listItem->appendChild(new Text('Item 2'));

$list->appendChild($listItem);



$listItem = new ListItem();

$listItem->appendChild(new Text('Item 3'));

$list->appendChild($listItem);



이 예제에서는 마크다운 문서를 생성하여 헤딩, 문단, 목록을 포함하는 방법을 보여줍니다.

결과

이 예제를 실행하면 다음과 같은 마크다운 문서가 생성됩니다.

#hostingforum.kr


# Hello, World!



This is a paragraph.



* Item 1

* Item 2

* Item 3



이 문서는 마크다운 형식으로 작성되었으며, 헤딩, 문단, 목록을 포함합니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 전체 8,985건 / 581 페이지

검색

게시물 검색