안녕하세요. 제 해결책을 공유하고 싶습니다.
인용문(quote) 관련 문제에 대해 말씀드리면, 앞서 말씀드린 것처럼 다음과 같은 상황에서 정규식(regexp)이 인용문을 올바르게 캡처하지 못하는 문제가 있었습니다:
- 사용자 이름과 게시글 ID가 이중 따옴표로 둘러싸여 있는 경우
- 중첩된 인용문(nested quotes)의 경우
저는 다른 로직을 사용하여 검색 및 치환을 수행하기로 결정했습니다. 태그와 그 내용을 검색하는 대신, 태그만 검색하는 정규식을 사용했습니다:
기존 코드:
raw.gsub!(%r{\[quote="?([^;]+);(\d+)"?\](.+?)\[\/quote\]}im) do
변경된 코드:
raw.gsub!(%r{(\[QUOTE(="?([^;]+);(\d+)"?)?\])|(\[\/QUOTE\])}im) do
그리고 인용문의 출처를 결정하는 부분을 조금 수정했습니다:
if $3 && $4
if topic_lookup = topic_lookup_from_imported_post_id(post_id)
post_number = topic_lookup[:post_number]
topic_id = topic_lookup[:topic_id]
"\n[quote=\"#{new_username},post:#{post_number},topic:#{topic_id}\"]\n"
else
"\n[quote=\"#{new_username}\"]\n"
end
elsif $5
"\n[/quote]\n"
end
또한, 스포일러(spoiler) 코드도 변경했습니다. 기존에는 다음과 같이 흐릿하게 처리된 텍스트를 사용했는데,
# [spoiler=Some hidden stuff]SPOILER HERE!![/spoiler]
raw.gsub!(%r{\[spoiler="?(.+?)"?\](.+?)\[/spoiler\]}im) do
"\n#{$1}\n[spoiler]#{$2}[/spoiler]\n"
end
이것을 details 태그로 변환하도록 변경했습니다:
raw.gsub!(%r{(\[spoiler(="?(.*?)"?)?\])|(\[\/spoiler\])}im) do
if $3
"\n[details=#{$3}]\n"
elsif $1
"\n[details]\n"
elsif $4
"\n[/details]\n"
end
end
vBulletin 환경에서는 스포일러가 흐릿하게 처리된 내용보다는 접혀 있는(collapsed) 내용을 의미하기 때문입니다. 따라서 vBulletin 가져오기 스크립트에서 스포일러를 흐릿한 스포일러 대신 details로 변환하는 것이 훨씬 적절하다고 생각합니다.
또한 mention 태그도 발견했습니다. 제 경우 vBulletin에서는 mention이 다음과 같이 보였습니다:
[mention=XXX]username[/mention]
스크립트에서 사용된 정규식은 태그 안에 사용자 ID가 포함될 수 있다는 점을 고려하지 않았습니다.
# [MENTION]<username>[/MENTION]
raw.gsub!(%r{\[mention\](.+?)\[/mention\]}i) do
new_username = get_username_for_old_username($1)
"@#{new_username}"
end
이 부분도 제 방식대로 수정했습니다:
# [MENTION]<username>[/MENTION]
raw.gsub!(%r{\[mention(=\d+)?\](.+?)\[/mention\]}i) do
new_username = get_username_for_old_username($2)
"@#{new_username}"
end


